How to unzip entire archive?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

How to unzip entire archive?

Post by ctflatt » Wed Mar 23, 2011 4:37 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to unzip entire archive?

Post by Klaus » Wed Mar 23, 2011 4:53 pm

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

Post Reply