CFloop through query and apply each result to a variable

235 views Asked by At

I'm drawing a bit of a blank at the moment on looping, so a pointer would be greatly appreciated.

  1. I'm running a query for a list of names in a table given before a specific time.

  2. I need to loop through those results and set a variable <cfset file2 = (result from query) so this code can execute:

    >  <cfexecute name="C:\Program Files
    > (x86)\neeviaPDF.com\PDFcompress\cmdLine\CLcompr.exe"
    > arguments="C:\inetpub\wwwroot\testingFolder\PDFCompression2\pdf\#arguments.file2#
    > C:\inetpub\wwwroot\testingFolder\PDFCompression2\pdf\ResultPDF3.pdf
    > -co -ci jpg -cq 10 -gi jpg -gq 10 -mi jbig2 -mq 1" outputfile="C:\inetpub\wwwroot\testingFolder\PDFCompression2\output.txt"
    > timeout="250"> </cfexecute>
    

It will then loop through the results of the query setting the variable file2 to each result, thus compressing the files with those names.

1

There are 1 answers

3
Alex On

This is the code which resolved my issue.

<cfquery name="qryGetFilesJustUploaded" datasource="#request.dsn#">                                         <!--- Limit to filed with pdf file type endings --->
SELECT fileupload
  FROM [First_Title_Services_Dev].[dbo].[upload_many]
  WHERE filedate >= '#dateTimeStamp#' AND fileupload Like '% .pdf'
</cfquery>

<!--- Next Set a loop function to run cfexecute--->
<cfloop query="qryGetFilesJustUploaded">
<cfset pdf_file_name = 'qryGetFileJustUploaded' />
<cfexecute name="C:\Program Files (x86)\neeviaPDF.com\PDFcompress\cmdLine\CLcompr.exe"
arguments="C:\inetpub\wwwroot\testingFolder\PDFCompression2\pdf\#pdf_file_name# C:\inetpub\wwwroot\testingFolder\PDFCompression2\pdf\#pdf_file_name# -co -ci jpg -cq 10 -gi jpg -gq 10 -mi jbig2 -mq 1"
outputfile="C:\inetpub\wwwroot\testingFolder\PDFCompression2\output.txt"
timeout="250">
</cfexecute>

</cfloop>