I have some cf code which is almost working I think.
I have the following structure:
work
--still-life
--portraits
--personal
In each of these folders there is the same structure:
still-life
--img-s
--img-m
--img-l
I want to know how many files are in the first directory (img-s)
for each of the pages that I am on /still-life/index.cfm
for example.
I have been trying to implement cfdirectory, but to no avail, then I found this code which is almost working:
<cfoutput>
directory="#GetDirectoryFromPath(GetTemplatePath())#"
</cfoutput>
<cfdirectory
directory="#GetDirectoryFromPath(GetTemplatePath())#"
name="myDirectory"
sort="name ASC, size DESC, datelastmodified">
<!---- Output the contents of the cfdirectory as a cftable ----->
<cftable
query="myDirectory"
colSpacing = "10"
htmltable
colheaders>
<cfcol
header="NAME:"
align = "Left"
width = 20
text="#Name#">
<cfcol
header="SIZE:"
align = "Left"
width = 20
text="#Size#">
<cfcol
header="date last modified:"
align = "Left"
width = 20
text="#datelastmodified#">
</cftable>
I am actually getting this in the output:
directory="{URL}\work\portraits\"
NAME: SIZE: date last modified:
img-l 0 {ts '2015-06-08 11:56:35'}
img-m 0 {ts '2015-06-08 11:56:35'}
img-s 0 {ts '2015-06-08 11:56:36'}
index.cfm 134 {ts '2015-06-08 11:56:36'}
So I think it is pretty close. I am wondering if I need a loop to go through the subdirectories?
If it helps I only really care about img-s directory and the files should always be jpg's.
I did try and implement some of the code from here and here as well as trying to implement ExpandPath function (but my CF experience is relatively limited).
EDIT
I've added this to the bottom of the cftable:
<cfcol
header="Count"
align="left"
width="20"
text="#recordCount#">
And now my output looks like this:
NAME: SIZE: date last modified: Count
img-l 0 {ts '2015-06-08 11:56:34'} 4
img-m 0 {ts '2015-06-08 11:56:34'} 4
img-s 4096 {ts '2015-06-08 14:10:33'} 4
index.cfm 1276 {ts '2015-06-08 14:13:53'} 4
So at least it is now reading the filesize of the directory.
EDIT 2
Just for @ScottStroz here is the current code:
<cfset filters = "*.jpg">
<cfdirectory
directory="#ExpandPath('.')#/img-s"
name="getSubDir"
recurse = "yes"
filter = "#filters#">
<cfset imgArray=arraynew(1)>
<cfset i=1>
<cfset imgDir="img-s/">
<cfset imgDirM="img-m/">
<cfloop query="getSubDir">
<cfset imgArray[i]=getSubDir.name>
<cfset i = i + 1>
</cfloop>
<ul class="workNav clearfix">
<cfloop from="1" to="#arrayLen(imgArray)#" index="i">
<cfoutput>
<li><a href="#imgDirM##imgArray[i]#"><img src="#imgDir##imgArray[i]#"/></a></li>
</cfoutput>
</cfloop>
</ul>
This code should work.
<cfoutput>
directory="#GetDirectoryFromPath(GetTemplatePath())#"
</cfoutput>
<cfdirectory
directory="#GetDirectoryFromPath(GetTemplatePath())#"
name="myDirectory"
sort="name ASC, size DESC, datelastmodified"
recurse = "yes">
<!---- Output the contents of the cfdirectory as a cftable ----->
<cftable
query="myDirectory"
colSpacing = "10"
htmltable
colheaders>
<cfcol
header="Count"
align="left"
width="20"
text="#recordCount#">
<cfcol
header="NAME:"
align = "Left"
width = 20
text="#Name#">
<cfcol
header="SIZE:"
align = "Left"
width = 20
text="#Size#">
<cfcol
header="date last modified:"
align = "Left"
width = 20
text="#datelastmodified#">
<cfcol
header="Directory"
align = "Left"
width = 20
text="#directory#">
</cftable>