Page 1 of 1

How to unzip entire archive?

Posted: Wed Mar 23, 2011 4:37 pm
by ctflatt
Is there a simple way to unzip the contents of a specific .zip file, or does the process have to iterate through a file list?

I am serving .zip files from a server to a specific directory. I would like to initiate an unzip from a button for the entire archive to the same directory. The containing folder will be created automatically from the .zip extraction.

Once the process is complete, I want to delete the original .zip file, leaving the extracted content intact.

Any direction would be greatly appreciated, as always.

Thanks!

:Todd

Re: How to unzip entire archive?

Posted: Wed Mar 23, 2011 4:53 pm
by Klaus
Hi Todd,

you will need to loop through the items in the archive!

This will get you started, check the docs for more info:

Code: Select all

...
## tArchive contains the path to the ZIP file
## tFolder = the TARGET folder for the files in the archive

## 1. Open archive for READ ONLY!
  revZipOpenArchive tArchive,"read"

## 2. Put contents of archive into a list
  put RevZipEnumerateItems(tArchive) into tList
  
## 3. Loop through all items in the ZIP archive and...
  repeat for each line i in tList

## Just to be sure, I saw ean empty line in the ENUMERATION list.
## May not be neccessary, but who knows? ;-)
    if i = empty then
      next repeat
    end if

## 4. ...save them into the target folder with the sameme filename as the original file 
    revZipExtractItemToFile tArchive,i,(tFolder & "/" & i)
  end repeat
  
## 5. Close archive
  revZipCloseArchive tArchive

## DONE! Now you can delete the ZIP file!
...
Of course you will need to check for error when unZIPPING but that's it basically,
hope that helps! :)


Best

Klaus