Xbasic

FILE.UNZIP Function

Syntax

Result_Flag as L = FILE.UnZip(C zipfilename[,C files[,C path[,c unzip_flags]]])

Arguments

zipfilenameCharacter

The name of the zip file. It is necessary to explicitly specify the .ZIP extension.

filesCharacter

A pattern that selects files from the zip file. Wildcards are allowed.

pathCharacter

The target directory for the unzipped files.

unzip_flagsCharacter

Additional flags to control how the zip file is decompressed. Available flags are listed below:

Flag
Meaning
"P"

Creates the same subfolder structure under Destination_Folder that the original files had.

Returns

Result_FlagLogical

Returns .T. if the operation is successful. Otherwise .F..

Description

Extract files from a zip file.

Discussion

The FILE.UNZIP() method extracts the files that match the mask from Zip_Filename, and places the files in the Output_Directory. If the files are successfully extracted, Result_Flag will be .T..

Examples: 

Extract files from backup.zip to c:\temp.

FILE.unzip("c:\backup.zip", "*.*", "c:\temp")

Extract .dbf files from backup.zip to c:\temp.

FILE.unzip("c:\backup.zip", "*.dbf", "c:\temp")
FILE.UNZIP does not support extracting password protected zip archives.

Extracting files with path information 

If the zip file was created with path information stored in the zip file, then the mask must include the path that is stored in the zip file. For example, using the FILE.ZIPLIST() method, you can see the internal name for all files in the zip file.

? FILE.ziplist("c:\backup.zip", "n" + crlf())
data/backup/Mesurements.Dbf
data/backup/Mesurements.Cdx
data/backup/Mesurements.Ddd
data/backup/Mesurements.Ddm
data/backup/Mesurements.Ddx

In the above example, the zip file contains path information. Therefore, to unzip a file ( measurements.dbf, for example) from this file you would use the command:

FILE.unzip("c:\backup.zip", "data\backup\measurements.dbf", "c:\temp")

Or, to unzip all of the files in this zip file:

FILE.unzip("c:\backup.zip", "data\backup\*.*", "c:\temp")

On the other hand, consider a zip file that was created without path information:

? FILE.ziplist("c:\backup.zip","n" + crlf())
Mesurements.Dbf
Mesurements.Cdx
Mesurements.Ddd
Mesurements.Ddm
Mesurements.Ddx

In this case, the mask will not include path information. For example:

FILE.unzip("c:\backup.zip", "measurements.dbf", "c:\temp")

Or, to unzip all of the files in this zip file:

FILE.unzip("c:\backup.zip", "*.*", "c:\temp")

See Also