ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Archive functions
  • Example 1: Extracting all the files from the archive
  • Example 2: Extracting all the files from the archive while displaying a progress bar
zipExtractAll (Example)
Example 1: Extracting all the files from the archive
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)Ajax The following code is used to extract all the files from an archive and to decompress them. The stored path of the files contains: the name of the directories, the name and extension of the file. The extracted files are copied onto diskettes ("A:\Archive").
// Declare and initialize the variables
DirectoryName is string
ArchiveName is string = "MyArchive"
CreationErrorCode is int
AdditionErrorCode is int
ErrorCodeExtract is int
 
// Create an archive
CreationErrorCode = zipCreate(ArchiveName, "C:\Directory\Archives\ArchivePdf.wdz")
IF CreationErrorCode = 0 THEN
// Select the directory
DirectoryName = fSelectDir("", "", "Directory to add")
// Add all the files found in the selected directory
// and subdirectories to the archive
AdditionErrorCode = zipAddDirectory(ArchiveName, DirectoryName, True, zipDirectory)
IF AdditionErrorCode = 0 THEN
  // Extract and decompress the files
    // The files are copied onto diskettes
  ErrorCodeExtract = zipExtractAll(ArchiveName, "A:\Archive")
  // Display an error message if the files were not extracted
IF ErrorCodeExtract <> 0 THEN
Error(zipMsgError(ErrorCodeExtract))
END
ELSE
    // Display an error message if the files have not been added
    Error(zipMsgError(AdditionErrorCode))
END
ELSE
// Display an error message if the archive was not created
  Error(zipMsgError(CreationErrorCode))
END
Example 2: Extracting all the files from the archive while displaying a progress bar
WINDEVUser code (UMC) The following code is used to extract all the files from an archive and to decompress them. The stored path of the files contains: the name of the directories, the name and extension of the file. The files are extracted into the current directory (zipDirectory constant). A progress bar is used to indicate the percentage of decompression. This progress bar will be displayed in the status bar.
// -- Declaration code of the window
GLOBAL
ArchiveName is string = "MyArchive"
 
// -- Click code on BTN_ExtractFile
// Initialization
DirectoryName is string
CreationErrorCode is int
AdditionErrorCode is int
ErrorCodeExtract is int
 
// Create an archive
CreationErrorCode = zipCreate(ArchiveName, "C:\Directory\Archives\ArchivePdf.wdz")
 
IF CreationErrorCode = 0 THEN
// Select the directory
DirectoryName = fSelectDir("", "", "Directory to add")
// Add all the files found in the selected directory
// and subdirectories to the archive
AdditionErrorCode = zipAddDirectory(ArchiveName, DirectoryName, True, zipDirectory)
IF AdditionErrorCode = 0 THEN
// Extract and decompress the files into the current directory
ErrorCodeExtract = zipExtractAll(ArchiveName, zipDirectory, Compression_ProgressBar)
IF ErrorCodeExtract <> 0 THEN
Error(zipMsgError(ErrorCodeExtract))
END
  ELSE
// Display an error message if the files have not been added
Error(zipMsgError(AdditionErrorCode))
  END
ELSE
// Display an error message if the archive was not created
Error(zipMsgError(CreationErrorCode))
END
 
// Internal procedure used for the progress bar.
INTERNAL PROCÉDURE Compression_ProgressBar(CurrentFile is string, Percentage is int)
IF Percentage < 100 THEN
ProgressBar(Percentage, 100, CurrentFile)
// Refresh the window
Multitask(-1)
ELSE
// The compression is over
ProgressBar()
END
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help