Link to home
Start Free TrialLog in
Avatar of D J
D JFlag for United States of America

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#.zip">
            <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>
Avatar of _agx_
_agx_
Flag of United States of America image

EDIT: What's the purpose of that code, in plain english? ie Why role does it play in the overall process?

Also, what leads you to believe the bolded section is what is slowing the code rather than looping?
Avatar of D J

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.
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#"
               />
Avatar of D J

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.
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#.zip">
            <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.
Avatar of D J

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 "..">
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?).
Avatar of D J

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#.zip"
      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\#DLname#")>
                <cfzip
                      action="zip"
                      file="c:\dwgbin\#dlname#.zip"
                      recurse="yes"
                      source="c:\dwgbin\#dlname#"
               />
         <!--- Otherwise, do something else --->
         <cfelse>
                not found ...  do something else here
         </cfif>
Avatar of D J

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
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of D J

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_
The cfdirectory is quicker? I'm very surprised. I'd expect it to be slower, since it potentially has to do more work.