PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example 1: Adding a file into an archive
  • Example 2: Adding a file into an archive while displaying a progress bar
zipAddFile (Example)
Example 1: Adding a file into an archive
WINDEVUser code (UMC) 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"
ErrorCodeCreation is int
ErrorCodeAddition is int
 
// Create an archive
// WINDEV code
ErrorCodeCreation = zipCreate(ArchiveName, "C:\MyDirectory\MyArchives\PdfArchive.wdz")
// WINDEV Mobile code
ErrorCodeCreation = zipCreate(ArchiveName, "\MyDirectory\MyArchives\PdfArchive.zip")
// Display an error message if the archive was not created
IF ErrorCodeCreation = 0 THEN
// Select the file to add
FileName = fSelect("", "", "File to add", ...
  "File to compress" + TAB + "*.*", "*" , fselOpen + fselExist)
// Add the selected file into the archive
ErrorCodeAddition = zipAddFile(ArchiveName, FileName, zipDrive)
// Display an error message if the file was not added
IF ErrorCodeAddition <> 0 THEN
Error(zipMsgError(ErrorCodeAddition))
END
ELSE
Error(zipMsgError(ErrorCodeCreation))
END
 
Example 2: Adding a file into an archive while displaying a progress bar
WINDEVUser code (UMC) 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 bar is used to indicate the percentage of compression. 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
ErrorCodeCreation is int
ErrorCodeAddition is int
EventNum is int
 
// Create an archive
ErrorCodeCreation = zipCreate(ArchiveName, "C:\MyDirectory\MyArchives\PdfArchive.wdz")
 
// Display an error message if the archive was not created
IF ErrorCodeCreation = 0 THEN
// Call the event
EventNum = Event("Dis_Compress_ProgressBar", WinInput(), compressProgressBar)
// Select the file to add
FileName = fSelect("", "", "File to add", ...
   "File to compress" + TAB + "*.*", "*", fselOpen + fselExist)
// Add the selected file into the archive
ErrorCodeAddition = zipAddFile(ArchiveName, FileName, zipNone)
// Display an error message if the file was not added
IF ErrorCodeAddition <> 0 THEN
Error(zipMsgError(ErrorCodeAddition))
END
// End of event
EndEvent(EventNum)
ELSE
Error(zipMsgError(ErrorCodeCreation))
END
 
// Procedure local to the window. This procedure is used to manage the progress bar.
PROCEDURE Dis_Compress_ProgressBar(wMessage, wParam, lParam)
IF wParam<100 THEN
ProgressBar(wParam, 100, zipCurrentFile(ArchiveName))
// Refresh the window
Multitask(-1)
ELSE
// The compression is over
ProgressBar()
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment