Friday, July 25, 2014

How to zip and unzip folders with password in Delphi

This code uses the component Abbrevia.
For download of the component click here.

To zip folder
Use the component TAbzipper in Abbrevia.

procedure Zip;
var
  sPath: String;
begin
  sPath := ExtractFilePath(Application.ExeName);
  Zipper.Password := 'yourpassword';
  Zipper.BaseDirectory := sPath + 'foldertozip' ;
  Zipper.FileName :=  sPath + 'foldertozip' + '.zip';
  Zipper.AddFiles('*.*', faAnyFile);
  Zipper.Save;
  Zipper.CloseArchive;
end;


To unzip folder 
Use the  component TAbUnZipper in Abbrevia.

procedure UnZip;
var
  sPath: String;
begin
  sPath := ExtractFilePath(Application.ExeName);
  if not DirectoryExists(sPath + 'unziplocation') then
    ForceDirectories(sPath + 'unziplocation');
  Unzipper.Password := 'yourpassword';
  Unzipper.FileName := sPath + 'foldertozip' + '.zip';
  Unzipper.BaseDirectory := sPath + 'unziplocation';
  Unzipper.ExtractFiles('*.*');
  Unzipper.CloseArchive;
end;

0 comments:

Post a Comment

 
Related Posts Plugin for WordPress, Blogger...