Scan all files in a directory and return counts by file type

只愿长相守 提交于 2019-12-02 10:15:38

For the first question, there's two approaches. Either loop over each of the different file types you're interested in, doing a cfdirectory for each.

<cfset filetypes = arrayNew(1)>
<cfset arrayAppend(filetypes, "js")>
<cfset arrayAppend(filetypes, "cfm")>
<cfset arrayAppend(filetypes, "pdf")>

<cfloop index="i" from="1" to="#arrayLen(filetypes)#">
    <cfdirectory
        action="list"
        directory="directory path" 
        name="Files"
        recurse = "yes"
        filter="*.#filetypes[i]#" />         
    <cfoutput>No of #filetypes[i]# files: #files.recordCount#<br></cfoutput>
</cfloop>

Or you can do multiple file types in one CFDirectory, see http://www.bennadel.com/blog/1221-CFDirectory-Filtering-Uses-Pipe-Character-For-Multiple-Filters-Thanks-Steve-Withington-.htm

<cfdirectory
    action="list"
    directory="directory path" 
    name="Files"
    recurse = "yes"
    filter="*.js|*.cfm|*.pdf" />         
<cfoutput>No of JS/CFM/PDF files: #files.recordCount#</cfoutput>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!