How to create and extract ZIP files in Delphi XE6?
Delphi provides System.Zip unit for creating ZIP files. System.Zip unit contains a simple ZIP extractor and creator class named TZIPFile. TZIPFile class mainly has three methods which are used to create and extract zip files:
ZipDirectoryContents: Creates the zipped file
IsValid: Validates the zip file
ExtractZipFile: Extracts the zip file
Following is the code snippet in Delphi to create a zip file.
uses System.Zip;
TZIPFile.ZipDirectoryContents('C:\FolderToZip', 'C:\ZippedFolder.zip');
Following is the code snippet in Delphi to extract a zip files.
uses System.Zip;
ZipFile := 'ZippedFolder.zip'; //This is my zip file
if TZipFile.IsValid(ZipFile) then //Validate zip file
begin
TZipFile.ExtractZipFile(ZipFile, 'C:\DestinationDirectory'); //Extract the zip file
end
else
begin
ShowMessage('Zip File is not valid');
end;
No comments:
Post a Comment