我有一些我认为几乎可以工作的cf代码。
我有以下结构:
work
--still-life
--portraits
--personal
在每个文件夹中都有相同的结构:
still-life
--img-s
--img-m
--img-l
(img-s)
例如,我想知道我所在的每个页面的第一个目录中有多少文件/still-life/index.cfm
。
我一直在尝试实现cfdirectory,但无济于事,然后我发现这段代码几乎可以工作:
<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>
我实际上在输出中得到了这个:
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'}
所以我认为它非常接近。我想知道是否需要一个循环来遍历子目录?
如果它有帮助,我只关心 img-s 目录,并且文件应该始终是 jpg 的。
我确实尝试从这里和这里实现一些代码,并尝试实现 ExpandPath 函数(但我的 CF 经验相对有限)。
编辑
我已将此添加到 cftable 的底部:
<cfcol
header="Count"
align="left"
width="20"
text="#recordCount#">
现在我的输出如下所示:
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
所以至少它现在正在读取目录的文件大小。
编辑 2
仅针对@ScottStroz,这是当前代码:
<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>