Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How can ColdFusion work with ZIP and JAR files?

Use the <cfzip> and the <cfzipparam> tags.

<cfzip> provides access to ZIP and JAR files with the following actions:

delete: Deletes one or more files from the file.

list: Lists the contents of the file.

read: Reads the contents of the file into a variable.

readBinary: Reads the contents of a binary archived file into a variable.

unzip: Extracts files from the ZIP or JAr file.

zip: Compress files into a ZIP or JAR file.

<cfzip file="c:/foo.jar" action="list" name="myVar">
<cfdump var="#myVar#">

Use the <cfzipparam> tag with the <cfzip> tag to zip, extract, or delete multiple files or directories. For example:

<!--- This example shows how to update a ZIP file with files from multiple locations, each with a different filter. --->
<cfzip file="c:\foo.jar" action="zip">
<cfzipparam source="c:\test1\file1.txt">
<cfzipparam source="c:\test2\test3" recurse="yes">
</cfzip>


This question was written by Jeremy Petersen.
It was last updated on December 12, 2007 at 12:09:25 PM EST.

CFML Referenced

<cfzip>
<cfzipparam>

Categories

File and Directory Access

Comments

Comment made by Jason West on May 27, 2008 at 2:19 PM
This tag is only found in Adobe CFML 8. What way would be best way for servers that are below version 8?


Comment made by Raymond Camden on May 27, 2008 at 2:30 PM
I would Google. I seem to remember a few cfzip type products that were available for CF.