【发布时间】:2015-06-23 17:54:34
【问题描述】:
如何循环查询并一次传递一个结果而不是所有结果?
我正在运行一个查询并使用<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" 时,查询中的每个文件名似乎都没有成功传入,因此可以返回该文件的文件路径。
- 是否转储查询以验证我的查询是否有效并且文件列表是否可用。
- 还验证了文件存在并且文件名中没有奇怪的格式。
【问题讨论】:
-
第 1 步 - 查看您的数据。具体来说,转储 qryGetFilesJustUploaded。
-
你可以使用expandpath()函数来设置源和目标吗?
标签: coldfusion coldfusion-9 cfloop cffile