I'm trying to loop through a folder on a server to get a list of specific files and then have those files copied to a temp directory or zipped and copied to a temp directory. However I keep running into wall as I'm not sure how to do this. (Still an amateur with ColdFusion)
so here I do a SQL Query where I retrieve the exact attachments from specific dates I am looking for:
<cfquery name="test" datasource="test" cachedwithin="#CreateTimeSpan(0,0,10,0)#" result="r">
SELECT Test.TestNum, Test1.Test1Date, TestReport.Attachment
FROM Test
INNER JOIN more SQL code here..
WHERE Test1.Test1Date >= '#daterangevariablehere#'
AND NOT more SQL code here as well..
ORDER BY Test.TestNum
</cfquery>
The SQL Query is correct as in SQL Server Mgmt Studio, it executes properly and even before I try to do a cfdump it shows the correct list of files I am trying to get. However when I try to loop through them to copy or zip them, it's a total fail -> blank page.
I tried to:
<cfloop query="test">
<cfif test.recordcount gt 0>
<cfzip action="zip" file="#LocationOfwhereIwantTheEndResult" source="#WhereTheFolderWithTheAttachmentsReside#">
</cfzip>
</cfloop>
I even tried to do this, wrapped around the above code:
<cfdirectory action="list" name="test" directory="#WhereTheFolderWithTheAttachmentsReside#"></cfdirectory>
Side note: some of the variables and code are made up for the sake of security and anonymity..but I wanted to show the structure of what I'm trying to accomplish I hope I was clear(!) if otherwise please do let me know and I will provide more detail or information. ANY help is really appreciated, I have been banging my head against a wall on this one and feel like it might be something super simple. Please help! :)
I suspect that your
file
andsource
locations are incorrect. UseExpandPath()
function to make sure its going to the correct place.