>我正在尝试循环访问.csv文件,具体取决于一列值,我进一步查看是否存在与列中的值同名的文件
我使用的代码如下:
<cffile action="read" file="C:/ColdFusion10/cfusion/wwwroot/kelly2/debitorders.csv" variable="csvfile">
<cfoutput>
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">
<cfif FileExists(ExpandPath(listgetAt('#index#',5).txt))>
xxx
</cfif>
#listgetAt('#index#',1)#<br>
#listgetAt('#index#',2)#<br>
#listgetAt('#index#',3)#<br>
#listgetAt('#index#',4)#<br>
#listgetAt('#index#',5)#<br>
#listgetAt('#index#',6)#<br>
#listgetAt('#index#',7)#<br>
#listgetAt('#index#',8)#<br>
</cfloop>
</cfoutput>
但是,当我运行它时,出现以下错误:
You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.
The error occurred in C:/ColdFusion10/cfusion/wwwroot/kelly2/upload.cfm: line 6
4 : <cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">
5 :
6 : <cfif FileExists(ExpandPath(listgetAt('#index#',5).txt))>
7 : xxx
8 : </cfif>
我尝试过将 CFIF 标签放入尝试并捕获,根据谷歌的说法,这为大多数人解决了这个问题,但它对我不起作用
试试这个
<cfif FileExists(ExpandPath("#listgetAt('#index#',5)#.txt"))>
而不是
<cfif FileExists(ExpandPath(listgetAt('#index#',5).txt))>