PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Example 1: Extracting a file from the archive based on its index
  • Example 2: Extracting a file according to its path while displaying a progress bar
zipExtractFile (Example)
Example 1: Extracting a file from the archive based on its index
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)Ajax The following code is used to extract a file from an archive and to decompress it. The stored path of the files contains: the name of the directories, the name and extension of the file (ZipDirectory constant). The extracted file is copied onto a diskette ("A:\Archive"). The file to extract is selected from a Table control populated programmatically (TABLE_ArchiveTable).
Caution: In order for the index of the Table control populated programmatically to match the index of the selected file, the Table control must not be sorted.
// Declare and initialize the variables
DirectoryName is string
ArchiveName is string = "MyArchive"
CreationErrorCode is int
AdditionErrorCode is int
ErrorCodeExtract is int
FileIndex 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
    // Select the file in the archive
    FileIndex = TableSelect(TABLE_ArchiveTable)
    // Extract and decompress the selected file
    // Copy the extracted file
    ErrorCodeExtract = zipExtractFile(ArchiveName, FileIndex, "C:\Temp\Archive")
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 a file according to its path while displaying a progress bar
WINDEVReports and QueriesUser code (UMC) The following code is used to extract a file from an archive and to decompress it. The stored path of the files contains: the name of the directories, the name and extension of the file (ZipDirectory constant). The file to extract is selected according to its stored path. The file is 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.
// --Global declarations of the window
GLOBAL
ArchiveName is string = "MyArchive"
// --Click on BTN_ExtractFile
// Initialization code
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 a file into the current directory
    ErrorCodeExtract = zipExtractFile(ArchiveName, ...
   "File.txt", zipDirectory, Comrpession_ProgressBar)
IF ErrorCodeExtract <> 0 THEN
Error(zipMsgError(ErrorCodeExtract))
END
EndEvent(EventNum)
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