显示目录及其文件

时间:2012-11-08 15:16:35

标签: coldfusion cfdirectory

我试图将指定路径中所有目录的输出以及每个目录中的文件分组。目前,我有:

    <cfset local.baseWebPath = ExpandPath( "./upload/views/files/" ) />
    <cfset custID = session.authUser.getuser_custid() />
    <cfset filters = "*.pdf|*.zip|*.doc*|*.ppt*|*.pps*|*.ai*|*.eps*|*.xls*|*.swf|*.rtf|*.psd|*.jpg|*.png|*.tif">

    <!---display directory for specific customer--->
        <cfdirectory 
            action = "list"
            directory = "#local.baseWebPath##left(custID, 5)#"
            name = "getFiles"
            filter = "#filters#" 
            recurse = "no"
            />
<cfoutput query="getFiles">
     <!---get the file name--->
     <cfset fname = ListFirst(getFiles.name, "." )>
     <!---get the file extenstion--->
     <cfset exten = ListLast(getFiles.name, ".")>
     <cfif getFiles.type eq "file" and getFiles.name neq "thumbs.db">
          <tr>
               <td align="absmiddle"><a href="#buildUrl('main.attachDownload?filename=#getFiles.name#')#">#fname#</a></td>
               <td align="absmiddle"><img src="/art/assets/images/fileTypes/#fileIcon#" title="#exten#"/></td>
               <td align="absmiddle">
                    <!---convert the file size from bytes into mb and kb--->
                    <cfif getFiles.size GT "1000000">
                         #numberformat(getFiles.size*.000001, 9.99)#Mb
                    <cfelse>
                         #numberformat(getFiles.size*.001, 9)#kb
                    </cfif>
               </td>
               <td align="absmiddle">#getFiles.dateLastModified#</td>
               <td align="absmiddle"><a href="#buildUrl('main.deleteFile?filename=#getFiles.name#')#" onClick="alert('Are you sure you want to delete this file?')"><img src="/art/assets/images/delete.png" title="delete file" /></a></td>
          </tr>
      </cfif> 
</cfoutput>    

    <!---display all directories and their files for admin--->
        <cfdirectory 
            action="list" 
            directory="#local.baseWebPath#" 
            name="allDirectories" 
            recurse="true"
            />

Diplaying个人客户目录运作良好。但是,当管理员登录时,应显示所有目录以及按客户分组的文件。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以使用查询查询来正确排序

<cfquery name="getFiles" dbtype="query">
SELECT name, size, datelastmodified, directory
FROM getFiles
ORDER BY directory
</cfquery>

然后您可以使用

<cfoutput query="getFiles" group="directory">
 #getFiles.directory# <!--- format to show only the custID --->
  <cfoutput>
   <!--- outupt table here --->
  </cfoutput>         
</cfoutput>