wwZipArchive::ZipFiles

Creates a zip file from a list of files.

Files can be added either as fully qualified files or file wildcards that can glom many files at once. Files or wildcards are separated by commas.

If you want to create a folder structure inside of the zip file - ie. capture the recursive file structure of the files imported - you can specify a base folder that acts as a the 'root' for the folder structure inside of the zip file. If you specify a base folder it becomes the root and all files added are added as relative files to this root in a zip folder structure. If no base path is provided files are added in flat format.

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

Return Value

.T. or .F. - check cErrorMsg for error

Parameters

lcZipFile
The Zip file to create

lcFiles
Files or file specs to include as a comma delimited list

  • Full path - c:\temp\test.prg or c:\temp*.prg
  • Relative Path - test.prg or *.prg,*.h The relative path behavoir depends on whether lcBaseFolder is provided or not. If provides the path is relative to the lcBaseFolder. If not provided the path is resolved using the current path and FoxPro path.
  • FileSpec - *.prg,*.md

lcBaseFolder
Required if you want your zip file to have a folder structure. If provided any relative file paths provided in lcFiles are relative to the base folder. If not provided, any partial paths are relative to the current path.

Note: You can add partial paths and wildcards that are associated with the base folder, and also add additional files using other fully qualified files. These other paths are added to the archive as folders prefixed with __.

Scenarios:

  • No lcBasePath - files are added without folder structure in the zip
  • lcBasePath set, relative paths only- all files are added using zip folder structure
  • lcBasePath set, full paths - Paths that are relative to base path are added using zip folder structure, others are added with __

llRecurse
Optional - if .T. the directory where the filespec is applied is recursed. Default is .F.

llFast
Optional - if .t. optimize for performance, if .f. optimize for size. Default .F.

Remarks

  • This is a standalone function not a method of the wwApi class
  • Depends on wwDotnetBridge and requires distribution of wwDotnetBridge.dll

Example

loZip = CREATEOBJECT("wwZipArchive")

*** Zip files using a base path using relative path wild cards recursively
? loZip.ZipFiles(;
   "d:\temp\zipfiles.zip",;
   "*.fpw,*.prg,*.dll,*.h",;
   CURDIR(),.T.)

*** Unzip into a folder
loZip.UnzipFolder("d:\temp\zipfiles.zip","d:\temp\unzipped")

See also:

Class wwApi | wwZipArchive::UnzipFolder | wwZipArchive::ZipFiles

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