我试图遍历一个.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标记放入try and catch中,据google称,这对大多数人来说都解决了这个问题,但是对我来说不起作用
试试这个
<cfif FileExists(ExpandPath("#listgetAt('#index#',5)#.txt"))>
代替
<cfif FileExists(ExpandPath(listgetAt('#index#',5).txt))>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句