0

ほとんど機能している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>
4

1 に答える 1

3

このコードは機能するはずです。

<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> 
于 2015-06-08T15:04:30.400 に答える