0

Is it possible to use cfzip to create a zip folder containing of a certain type. I need to do this to take out .bak files from a folder with different filetypes and insert them into a zip folder.

Thanks

Colin

colinam1992
  • 338
  • 1
  • 3
  • 13
  • 3
    http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Tags_u-z_5.html Shows an example of the delete action with the filter attribute to delete certain extensions. Or when you create the zip file you can use the filter attribute to only zip files of a certain type and omit the ones you dont want – steve Mar 13 '15 at 15:06
  • @steve - Those are sound suggestions, particularly the latter. You should post that as an answer. – Leigh Mar 13 '15 at 16:15

1 Answers1

1

Steve already pointed you to the CF documentation which has example of delete. To create a zip, the simplest way is as follows:

<cfset fileName = createUUID() />
<cfzip file="D:\#fileName#.zip" action="zip" 
       source="D:\myfolder" 
       filter="*.bak" 
       recurse="No" >

If you want to add the files of a sub-directory, then make recurse="yes". To filter multiple file types you can simply use comma separated file type in filter like this filter="*.jpg, *.gif, *.png"

Note: I have used dynamic file name in case you want to run this script multiple times and have different file name, or multiple users are accessing this script at the same time.

Leigh
  • 28,765
  • 10
  • 55
  • 103
Keshav jha
  • 1,356
  • 8
  • 22