如何遍历查询并一次传递一个结果而不是所有结果?
我正在运行查询并使用<cfloop>
循环遍历结果,对于查询中的每个文件名,<cffile>
需要将该文件从一个文件夹移动到下一个文件夹,如下所示:
cfquery name="qryGetFilesJustUploaded" datasource="#request.dsn#"> <!--- Limit to filed with pdf file type endings --->
SELECT fileupload
FROM [DevDBServer].[dbo].[upload_many]
WHERE (fileupload Like '%.pdf%') and (needs_compression = '1')
</cfquery>
cffunction name="MoveCompressReturnFile" access="public" returntype="void" description="Moves file to temp folder, compresses it then returns it to its original location">
<!---Lets Loop through and move all files references in query--->
<cfloop query="#qryGetFilesJustUploaded#">
<cffile action="move"
source="C:\inetpub\wwwroot\testingFolder\PDFCompression\pdf\#qryGetFilesJustUploaded.fileupload#"
destination="C:\inetpub\wwwroot\testingFolder\PDFCompression\bin" >
<!--- Now lets compress it--->
<cfexecute name="C:\Program Files (x86)\neeviaPDF.com\PDFcompress\cmdLine\CLcompr.exe"
arguments="C:\inetpub\wwwroot\testingFolder\PDFCompression\bin\#qryGetFilesJustUploaded.fileupload# C:\inetpub\wwwroot\testingFolder\PDFCompression\bin\#qryGetFilesJustUploaded.fileupload# -co -ci jpg -cq 10 -gi jpg -gq 10 -mi jbig2 -mq 1"
outputfile="C:\inetpub\wwwroot\testingFolder\PDFCompression\bin\output.txt"
timeout="250">
</cfexecute>
<!---Now Lets Return the file back to its original folder--->
<cffile action="move"
source="C:\inetpub\wwwroot\testingFolder\PDFCompression\bin\#qryGetFilesJustUploaded.fileupload#"
destination="C:\inetpub\wwwroot\testingFolder\PDFCompression\pdf" >
</cfloop>
</cffunction>
当谈到运行第一个 cffile 命令时,我收到一条错误消息,指出 C:.... C:.... 不是有效的源,看起来它所做的是一次指定多个文件而不是而不是一次抓取一个,直到完成抓取查询中引用的所有文件。我该如何解决?
更新:代码未成功循环查询结果。1. 使用 filename="document1.pdf" 测试代码,将其传递给 FindFilePath 方法并带回文件路径并执行其余代码没有问题。但是,当将其替换为 filename="qryGetFilesJustUploaded" 时,查询中的每个文件名似乎都没有成功传入,因此可以返回该文件的文件路径。
- 是否转储了查询以验证我的查询是否有效并且文件列表可用。
- 还验证了文件存在并且文件名中没有奇怪的格式。