Class wwZipArchive

Provides Zip archive functionality for creating and extracting of zip files.

Using this class you can:

  • Add files in batch using paths or wildcards optionally recursively
  • Append files
  • Unzip an archive into a folder
  • Unzip individual files
  • Get a listing of all files and selectively extract files

Remarks

  • This library uses wwDotnet bridge
  • Dependencies:
    • wwipstuff.dll
    • wwDotnetBridge.dll

Class Members

MemberDescription

AppendFiles

Appends files to an existing zip file or creates a new zip file if it doesn't exist.

AppendFiles(lcZipFile,lcFiles, lcBaseFolder, llRecurse, llFast)

GetZipEntries

Get a list of entries for the files contained inside of the zip file as a FoxPro Collection. Use this method to manually check the content of a zip file or selectively extract files.

o.GetZipEntries(lcZipFile)

UnzipFile

Retrieves an individual file from a zip archive and saves it to disk.

o.UnzipFile(lcZipFile, lcEntry, lcTargetFile)

UnzipFolder

Unzips the complete contents of a Zip file into a folder. If the Zip file contains folder structure, the output is created using that structure. If the folder doesn't exist it is created.

o.UnzipFolder(lcZipFile, lcTargetFolder)

ZipFiles

Creates a zip file from a list of files.

ZipFiles(lcZipFile,lcFiles,lcBaseFolder, llRecurse,llFast)

Example

DO wwZipArchive  && Load library and dependencies

loZip = CREATEOBJECT("wwZipArchive")
lcZipFile = "d:\temp\zipFiles.zip"

*** Zip up a folder with multiple wildcards
IF !loZip.ZipFiles(;
   lcZipFile,;
   "*.fpw,*.vc?,*.dll,*.h",;  
   CURDIR(), .T.)
   ? "Zipping Error: " + loZip.cErrorMsg
   RETURN
ENDIF   
? loZip.cErrorMsg
   
*** add another file
*** Note: You can add many files using same syntax as ZipFiles() above
IF !loZip.AppendFiles(lcZipFile, "wwZipArchive.prg")
   ? "Error: " + loZip.cErrorMsg
   RETURN
ENDIF
   
*** Unzip all into a folder   
IF !loZip.UnzipFolder(lcZipFile, "d:\temp\Unzipped1")
   ? "Unzip Error: " + loZip.cErrorMsg
   RETURN
ENDIF

*** Look at all files in the zip   
loEntries = loZip.GetZipEntries(lcZipFile)
IF ISNULL(loEntries)
   ? "No entries:  " + loZip.cErrorMsg
   RETURN 
ENDIF
? loEntries.Count

*** Iterate through the collection
FOR EACH loEntry IN loEntries FoxObject     
	? loEntry.Name + "  " + ;
	  loEntry.Fullname + " " + ;
	  TRANSFORM(loEntry.Length) + " - " + ;
	  TRANSFORM(loEntry.CompressedLength)
ENDFOR   

*** Unzip an individual entry and unzip it - first in this case
loZip.UnzipFile(lcZipFile, loEntries[1].FullName, "d:\temp\" + loEntries[1].Name)

© West Wind Technologies, 1996-2024 • Updated: 06/06/24
Comment or report problem with topic