Bryant Web Consulting

CFZIP Part 1: Introduction

CFZIP is powerful and easy to use. Better than that, it can work with zip files or jar files in just the same way.

Listing the Contents of a Zip file 

Finding out what is in a zip file is now as easy as everything else in ColdFusion:

<cfzip action="list" file="C:\software\DataMgr\DataMgr_2_0_2.zip" name="qFiles">

This will return a recordset similar to the recordset returned from CFDIRECTORY.

Reading a File in a Zip File

You can also read a file from within the zip file without unzipping the file. So, if I wanted to read the contents of DataMgr.cfc from the above file:

<cfzip
  action="read"
  entrypath="DataMgr.cfc"
  file="C:\software\DataMgr\DataMgr_2_0_2.zip"
  variable="DataMgrFile"
>

To read a binary file, use the same code, but change the action to "readBinary".

Unzipping a file

To unzip a file, just tell CFZIP where to put the files. 

<cfzip
  action = "unzip"
  file = "C:\software\DataMgr\DataMgr_2_0_2.zip"
  destination = "C:\software\DataMgr\unzip\"
>

Zipping a file

Zipping is file is easy as well:

<cfzip
  file="C:\software\DataMgr\DataMgr_ZipTest.zip"
  source="C:\software\DataMgr\unzip\"
>

At this point, you might be thinking that this doesn't provide you enough options. In fact, CFZIP provides many more options than I showed here. It has several more optional attributes as well as a a CFZIPPARAM tag to give you more flexibility. All of which I will try to cover in a future entry.

Alternatives

If you need the ability to deal with zip files now, there are other alternatives to CFZIP:

Make sure that you check the licensing restrictions on all of these before you use them.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)