PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN

  • Example 1: Adding all the files found in a directory and in its sub-directories into an archive
  • Example 2: Adding all the files found in a directory into an archive while displaying a progress bar
zipAddDirectory (Example)
Example 1: Adding all the files found in a directory and in its sub-directories into an archive
WINDEVWEBDEV - Server codeUser code (UMC)Ajax The following code is used to add all the files found in a directory and in its sub-directories into an archive. The directory is selected by the user with fSelectDir. The full path of the file is stored in the archive.
// Declare and initialize the variables
DirectoryName is string
ArchiveName is string = "MyArchive"
CreationErrorCode is int
AdditionErrorCode is int
 
// Create an archive
CreationErrorCode = zipCreate(ArchiveName, "C:\MyDirectory\MyArchives\PdfArchive.wdz")
 
// Display an error message if the archive was not created
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, zipDrive)
 
// Display an error message if the files have not been added
IF AdditionErrorCode <> 0 THEN
 Error(zipMsgError(AdditionErrorCode))
END
ELSE
Error(zipMsgError(CreationErrorCode))
END
Example 2: Adding all the files found in a directory into an archive while displaying a progress bar
WINDEVUser code (UMC) The following code is used to add all the files found in a directory into an archive. The directory is selected by the user with fSelectDir. The different directories found in the file path as well as the file name and extension are stored in the archive. A progress indicates the compression percentage. This progress bar will be displayed in the status bar.
// -- Global declarations of the window
GLOBAL
ArchiveName is string = "MyArchive"
// -- Click on BTN_AddDirectory
// Initialize the variables
DirectoryName is string
CreationErrorCode is int
AdditionErrorCode is int
 
// Create an archive
CreationErrorCode = zipCreate(ArchiveName, "C:\MyDirectory\MyArchives\PdfArchive.wdz")
 
// Display an error message if the archive was not created
IF CreationErrorCode = 0 THEN
// Select the directory
DirectoryName = fSelectDir("", "", "Directory to add")
// Adds all the files found in the selected directory into the archive
ErrorCodeAddition = zipAddDirectory(ArchiveName, DirectoryName, False, zipDirectory, ...
zipAddDirectory_Callback, zipAddDirectoryProgressBar_Callback)
// Display an error message if the file was not added
IF AdditionErrorCode <> 0 THEN
Error(zipMsgError(AdditionErrorCode))
END
ELSE
Error(zipMsgError(CreationErrorCode))
END
 
// Procedure for selecting files
// In this example, all files are taken into account
INTERNAL PROCEDURE zipAddDirectory_Callback(FileName is string)
RETURN True
END
 
 
// This procedure is used to manage the progress bar.
INTERNAL PROCEDURE zipAddDirectoryProgressBar_Callback(CurrentFile is string,
OverallProgress is int, FileProgress is int)
IF OverallProgress < 100 THEN
ProgressBar(OverallProgress, 100, CurrentFile)
// Refresh the window
Multitask(-1)
ELSE
ProgressBar()
END
END
Minimum version required
  • Version 9
Comments
Click [Add] to post a comment