通过cfquery循环进行文件移动失败

时间:2015-06-23 17:54:34

标签: coldfusion coldfusion-9 cfloop cffile

如何循环查询并一次传递一个结果而不是所有结果?

我正在运行查询并使用public class Random { public static void main(String[] args) { String licensestring = "MKDC-"; char license[] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9' }; int x = 0; while (x < 16){ java.security.SecureRandom rand = new java.security.SecureRandom(); int randomNumber = rand.nextInt(36); licensestring = licensestring + license[randomNumber]; x = x + 1; if (x == 4 || x == 8 || x == 12){ licensestring = licensestring + "-"; } } System.out.println(licensestring); } } 循环查看结果,对于查询中的每个文件名,<cfloop>需要将该文件从一个文件夹移动到下一个文件夹,如下所示: / p>

<cffile>

当谈到运行第一个cffile命令时,我收到一条错误消息:C:.... C:....不是一个有效的源,它看起来像是指定多个文件一次而不是一次抓取一个,直到抓住查询中引用的所有文件。我该如何解决?

更新:代码未成功循环查询结果。 1.使用filename =“document1.pdf”测试代码,它可以正常工作,将其传递到FindFilePath方法并返回文件路径并执行其余代码。但是当它被filename =“qryGetFilesJustUploaded”替换时,查询中的每个文件名似乎都没有成功传递,因此可以返回该文件的文件路径。

  1. 转储查询以验证我的查询是否正常并且文件列表可用。
  2. 还验证了文件的存在以及文件名中没有奇怪的格式。

2 个答案:

答案 0 :(得分:2)

您可以尝试在每个文件操作后放置sleep(5000)。这是因为文件操作需要一些时间才能完成。并且有可能在第一个文件操作进行时,下一个文件操作开始。因此,在某些情况下,您可能会遇到此类问题。试试这个。

<cfloop query="#qryGetFilesJustUploaded#">
    <cffile action="move" source="C:\inetpub\wwwroot\testingFolder\PDFCompression\pdf\#qryGetFilesJustUploaded.fileupload#"
    destination="C:\inetpub\wwwroot\testingFolder\PDFCompression\bin" >
    <cfset sleep(5000)>
    <!--- 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>
    <cfset sleep(5000)>
    <!---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" >
    <cfset sleep(5000)>
</cfloop>

答案 1 :(得分:-1)

<强>解决

当我将查询设置为文件名时,我忘记将其设置为“queryname.columnname”语法。

工作代码:

<cffunction name="testFunc" access="public">

<!--Lets Get the file names from the DB table--->
<cfquery name="qryGetFilesJustUploaded" datasource="#request.dsn#"> 
    SELECT fileupload
    FROM [First_Title_Services_Dev].[dbo].[upload_many]
    WHERE (fileupload Like '%.pdf%') and (needs_compression = '1')
    </cfquery>
    <cfset qryRecordCount = #qryGetFilesJustUploaded.RecordCount# >

<!--Set the methods and variables--->
<cfset fileSys = CreateObject('component','cfc.FileManagement')>

<cfloop query="qryGetFilesJustUploaded" startRow="1" endRow="#qryRecordCount#">
<cfset filename="#qryGetFilesJustUploaded.fileupload#" >
<cfset filePath = #fileSys.FindFilePath('#filename#','file')# >
<cffile action="move" source="#filePath#" destination="C:\compressionBin">
<cfset sleep(5000)>

<!---Compress the file now--->
<cfexecute name="C:\Program Files (x86)\neeviaPDF.com\PDFcompress\cmdLine\CLcompr.exe"
arguments="C:\compressionBin\#filename# C:\compressionBin\#filename# -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>
<cfset sleep(5000)>
<!---Lets Return the file now--->
<!---Back to where you came from! :D--->
<cffile action="move" 
source="C:\compressionBin\#filename#" destination="#filePath#" >
<cfset sleep(5000)>
</cfloop>
</cffunction>