PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Example 1: Adding a file to an archive
  • Example 2: Adding a file into an archive while displaying a progress bar
zipAddFile (Example)
Example 1: Adding a file to an archive
WINDEV The following code is used to add a file into an archive. The file is selected by the user with fSelect. The full path of the file is stored in the archive.
// Declare and initialize the variables
FileName is string
ArchiveName is string = "MyArchive"
CreationErrorCode is int
AdditionErrorCode is int
 
// Create an archive
// WINDEV code
CreationErrorCode = zipCreate(ArchiveName, "C:\MyDirectory\MyArchives\PdfArchive.wdz")
// WINDEV Mobile code
CreationErrorCode = zipCreate(ArchiveName, "\MyDirectory\MyArchives\PdfArchive.zip")
// Display an error message if the archive was not created
IF CreationErrorCode = 0 THEN
// Select the file to add
FileName = fSelect("", "", "File to add", ...
  "File to compress" + TAB + "*.*", "*" , fselOpen + fselExist)
// Add the selected file to the archive
AdditionErrorCode = zipAddFile(ArchiveName, FileName, zipDrive)
// Display an error message if the file was not added
IF AdditionErrorCode <> 0 THEN
Error(zipMsgError(AdditionErrorCode))
END
ELSE
Error(zipMsgError(CreationErrorCode))
END
Example 2: Adding a file into an archive while displaying a progress bar
WINDEV The following code is used to add a file into an archive. The file is selected by the user with fSelect. Only the name of the file is stored in the archive. A progress indicates the compression percentage. This progress bar will be displayed in the status bar.
// --Code for window creation
GLOBAL
ArchiveName is string = "MyArchive"
 
// --Click code on BTN_AddFile
// Initialization code
FileName 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 file to add
FileName = fSelect("", "", "File to add", ...
   "File to compress" + TAB + "*.*", "*", fselOpen + fselExist)
// Add the selected file to the archive
AdditionErrorCode = zipAddFile(ArchiveName, FileName, zipNone, Compression_ProgressBar)
// Display an error message if the file was not added
IF AdditionErrorCode <> 0 THEN
Error(zipMsgError(AdditionErrorCode))
END
ELSE
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
Comments
Click [Add] to post a comment