D J
asked on
ColdFusion Need assistance updating my legacy zip function
The legacy CF statements in bold are slowing my zip function process, how can I update the statements in bold with new CF statements?
<!--- Create the .ZIP file --->
<CFDIRECTORY DIRECTORY="c:\bin\#dlname# " NAME="test4files">
<CFLOOP QUERY="TEST4FILES">
<CFIF #TEST4FILES.TYPE# eq "Dir" AND #TEST4FILES.NAME# NEQ "." AND #TEST4FILES.NAME# NEQ "..">
<CFSET ChkDir3="c:\bin\#DLname#.z ip">
<CFIF DirectoryExists(chkdir3)>
<CFFILE ACTION="Delete" FILE="c:\bin\#dlname#.zip" >
</CFIF>
<cfzip
action="zip"
file="c:\bin\#dlname#.zip"
recurse="yes"
source="c:\bin\#dlname#"
/>
</CFIF>
</CFLOOP>
<!--- Create the .ZIP file --->
<CFDIRECTORY DIRECTORY="c:\bin\#dlname#
<CFLOOP QUERY="TEST4FILES">
<CFIF #TEST4FILES.TYPE# eq "Dir" AND #TEST4FILES.NAME# NEQ "." AND #TEST4FILES.NAME# NEQ "..">
<CFSET ChkDir3="c:\bin\#DLname#.z
<CFIF DirectoryExists(chkdir3)>
<CFFILE ACTION="Delete" FILE="c:\bin\#dlname#.zip"
</CFIF>
<cfzip
action="zip"
file="c:\bin\#dlname#.zip"
recurse="yes"
source="c:\bin\#dlname#"
/>
</CFIF>
</CFLOOP>
ASKER
_agx_ The overall role is to zip up all the folders/files that the user selected from the search query results. The bold part just checks for the folder, if no folder is present the zip function is skipped and a message is displayed no documents found.
When I remove the bold loop-checking folder part, the zip processed is cut in half. I.E. 50MB download is 30 seconds in lieu of 60 seconds.
When I remove the bold loop-checking folder part, the zip processed is cut in half. I.E. 50MB download is 30 seconds in lieu of 60 seconds.
Not sure I see the purpose of looping. Since the #dlname# variable isn't part of the query, its value won't change. Seems like a single zip command would do the same thing, ie zip the contents of a folder recursively:
<cfzip
action="zip"
file="c:\bin\#dlname#.zip"
recurse="yes"
source="c:\bin\#dlname#"
/>
<cfzip
action="zip"
file="c:\bin\#dlname#.zip"
recurse="yes"
source="c:\bin\#dlname#"
/>
ASKER
If I just use the zip command without the folder checking, I will receive an error because the zip command will try to zip without any folder to zip.
If a folder is not found, the zip function will not engage moving to cfelse displaying "no files found for this download" search.
If a folder is not found, the zip function will not engage moving to cfelse displaying "no files found for this download" search.
Edit: Hm... but the loop is checking the same thing every time (plus it's not even a folder), ie:
<CFSET ChkDir3="c:\bin\#DLname#.z ip">
<CFIF DirectoryExists(chkdir3)>
...
Assuming #DLname# really is a folder, there's no reason to do it inside the loop. Just check it once. Then call cfzip.
<CFSET ChkDir3="c:\bin\#DLname#.z
<CFIF DirectoryExists(chkdir3)>
...
Assuming #DLname# really is a folder, there's no reason to do it inside the loop. Just check it once. Then call cfzip.
ASKER
Thanks _agx_ - works great without the loop!
Is their and updated code method for the following line:
<CFIF #TEST4FILES.TYPE# eq "Dir" AND #TEST4FILES.NAME# NEQ "." AND #TEST4FILES.NAME# NEQ "..">
Is their and updated code method for the following line:
<CFIF #TEST4FILES.TYPE# eq "Dir" AND #TEST4FILES.NAME# NEQ "." AND #TEST4FILES.NAME# NEQ "..">
EDIT: You don't need it. Used to be when you did a directory listing on windows, CF would include "." (current directory) and ".." (parent directory) in the results. Like when you run DIR from a command prompt. However, CF stopped doing that a while ago (probably MX6?).
ASKER
Still having issues:
The zip function is not being triggered with the following:
<CFSET ChkDir3="c:\dwgbin\#DLname #">
<!---<CFIF DirectoryExists(chkdir3)> *old* need to look inside folder --->
<CFIF FileExists(chkdir3)> <!--- Is there a file in the folder? if yes run zip function --->
<cfzip
action="zip"
file="c:\dwgbin\#dlname#.z ip"
recurse="yes"
source="c:\dwgbin\#dlname# "
/>
</CFIF>
The zip function is not being triggered with the following:
<CFSET ChkDir3="c:\dwgbin\#DLname
<!---<CFIF DirectoryExists(chkdir3)> *old* need to look inside folder --->
<CFIF FileExists(chkdir3)> <!--- Is there a file in the folder? if yes run zip function --->
<cfzip
action="zip"
file="c:\dwgbin\#dlname#.z
recurse="yes"
source="c:\dwgbin\#dlname#
/>
</CFIF>
I think you meant to use DirectoryExists here:
<!--- If the directory to be zipped exists, go ahead ....--->
<cfif DirectoryExists("c:\bin\#D Lname#")>
<cfzip
action="zip"
file="c:\dwgbin\#dlname#.z ip"
recurse="yes"
source="c:\dwgbin\#dlname# "
/>
<!--- Otherwise, do something else --->
<cfelse>
not found ... do something else here
</cfif>
<!--- If the directory to be zipped exists, go ahead ....--->
<cfif DirectoryExists("c:\bin\#D
<cfzip
action="zip"
file="c:\dwgbin\#dlname#.z
recurse="yes"
source="c:\dwgbin\#dlname#
/>
<!--- Otherwise, do something else --->
<cfelse>
not found ... do something else here
</cfif>
ASKER
I think you meant to use DirectoryExists here:
I actually need to check the directory and if a file is in the directory - if yes zip
If just a empty directory - don't zip
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both solutions worked great; the top solution is 5 seconds quicker than the bottom solution downloading 70MB of data: 1:00 compared to 1:05
Thanks _agx_
Thanks _agx_
The cfdirectory is quicker? I'm very surprised. I'd expect it to be slower, since it potentially has to do more work.
Also, what leads you to believe the bolded section is what is slowing the code rather than looping?