Zip functionalities
Adding Files to Zip
In some projects there might be many files generated which needs to be added as an archive and send to a client or transferred to a specific pre-defined directory. We have ZipCreate and ZipAddDirectory function for this in windev
ZipCreate
ZipCreate function is used to create an Archive with the mentioned name.
ZipAddFile
Adds a file (of any type) into an archive
ZipAddDirectory
Adds all the files in a Directory to the Archive
// Create the archive
ResCreate = zipCreate("MyArchive", "C:\Temp\Archive.zip")
IF ResCreate = 0 THEN
// Add a file into an archive
ResAddFile = zipAddFile("MyArchive", ...
"C:\MyDirectory\MyFiles\File.pdf", zipDrive)
//adds all the files in the directory to the archive
ResAddDir = zipAddDirectory("MyArchive", ...
"C:\MyDirectory\MyFiles", True, zipDrive)
END
// Display an error message if the file was not added
IF ResAddFile <> 0 THEN
Error(zipMsgError(ResAddFile))
END
Extracting Files from Zip
There may be a need to extract files from Zip. For this we need to open the Zip file using ZipOpen with the filename. ZipExtractAll is used to retrieve all the files from the Zip file and finally close the zip using ZipClose function.
Example
// Open an archive
ResOpenArchive = zipOpen("Archive", sFIleName)
IF ResOpenArchive = 0 THEN
// Extract a file to its initial location
ResExtractFile = zipExtractAll("Archive",fExeDir(),True)
// Display an error message if the files were not extracted
IF ResExtractFile <> 0 THEN
Error(zipMsgError(ResExtractFile))
END
END
zipClose("Archive") //close the zip file
In some projects there might be many files generated which needs to be added as an archive and send to a client or transferred to a specific pre-defined directory. We have ZipCreate and ZipAddDirectory function for this in windev
ZipCreate
ZipCreate function is used to create an Archive with the mentioned name.
ZipAddFile
Adds a file (of any type) into an archive
ZipAddDirectory
Adds all the files in a Directory to the Archive
// Create the archive
ResCreate = zipCreate("MyArchive", "C:\Temp\Archive.zip")
IF ResCreate = 0 THEN
// Add a file into an archive
ResAddFile = zipAddFile("MyArchive", ...
"C:\MyDirectory\MyFiles\File.pdf", zipDrive)
//adds all the files in the directory to the archive
ResAddDir = zipAddDirectory("MyArchive", ...
"C:\MyDirectory\MyFiles", True, zipDrive)
END
// Display an error message if the file was not added
IF ResAddFile <> 0 THEN
Error(zipMsgError(ResAddFile))
END
Extracting Files from Zip
There may be a need to extract files from Zip. For this we need to open the Zip file using ZipOpen with the filename. ZipExtractAll is used to retrieve all the files from the Zip file and finally close the zip using ZipClose function.
Example
// Open an archive
ResOpenArchive = zipOpen("Archive", sFIleName)
IF ResOpenArchive = 0 THEN
// Extract a file to its initial location
ResExtractFile = zipExtractAll("Archive",fExeDir(),True)
// Display an error message if the files were not extracted
IF ResExtractFile <> 0 THEN
Error(zipMsgError(ResExtractFile))
END
END
zipClose("Archive") //close the zip file
Comments
Post a Comment