扫描文件夹并输出 coldfusion 中的所有文件名
Scan folder and output all file names in coldfusion
我正在尝试扫描文件夹中的所有文件并输出它们的文件名。我这里的代码只输出该文件类型的第一个文件名
<cfset filetypes = arrayNew(1)>
<cfset arrayAppend(filetypes, "jpg")>
<cfset arrayAppend(filetypes, "txt")>
<cfset arrayAppend(filetypes, "pdf")>
<cfloop index="i" from="1" to="#arrayLen(filetypes)#">
<cfdirectory
action="list"
directory="filepath"
name="Files"
recurse = "yes"
filter="*.#filetypes[i]#" />
<cfoutput>files: #Files.name#<br></cfoutput>
</cfloop>
我的代码出了什么问题?
您没有循环播放文件...
它 returns 一个要迭代的对象...我相信是一个查询。
所以像下面这样循环
<Cfoutput query="Files">
#Files.name# <br>
</cfoutput>
我正在尝试扫描文件夹中的所有文件并输出它们的文件名。我这里的代码只输出该文件类型的第一个文件名
<cfset filetypes = arrayNew(1)>
<cfset arrayAppend(filetypes, "jpg")>
<cfset arrayAppend(filetypes, "txt")>
<cfset arrayAppend(filetypes, "pdf")>
<cfloop index="i" from="1" to="#arrayLen(filetypes)#">
<cfdirectory
action="list"
directory="filepath"
name="Files"
recurse = "yes"
filter="*.#filetypes[i]#" />
<cfoutput>files: #Files.name#<br></cfoutput>
</cfloop>
我的代码出了什么问题?
您没有循环播放文件... 它 returns 一个要迭代的对象...我相信是一个查询。
所以像下面这样循环
<Cfoutput query="Files">
#Files.name# <br>
</cfoutput>