VCLZIP 操作的一个公用单元


unit uVclZipPublic;

interface

uses SysUtils, Variants, Classes,VCLZip,VCLUnZip;

function ZipFiles(zipControl:TVCLZip;Files:TStrings;MyZipName:string):Boolean;
function UnZipFiles(zipControl:TVCLZip;MyZipName,MyDestDir:string):Boolean;
function ZipDir(zipMode{0-连同根目录一起压缩,1-压缩指定目录中的所有文件和文件夹}:Integer;zipControl:TVCLZip;MyZipName,MyZipDir:string):Boolean;

implementation

function ZipFiles(ZipControl:TVCLZip;Files:TStrings;MyZipName:string):Boolean;
begin
  Result:=False;
  try
  with ZipControl do
  begin
  FilesList.Text:=Files.Text;
  ZipName:=MyZipName;
  Zip;
  Result:=True;
  end;
  except
  //Showmessage('');
  end;
end;

function UnZipFiles(zipControl:TVCLZip;MyZipName,MyDestDir:string):Boolean;
begin
  Result:=False;
  try
  with zipControl do
  begin
  ZipName:=MyZipName;
  ReadZip;
  DestDir:=MyDestDir;
  OverwriteMode:=Always;
  RelativePaths:=True;
  RecreateDirs:=True;
  DoAll:=True;

  FilesList.Add('*.*');
  UnZip;
  Result:=True;
  end;
  except

  end;
end;

function ZipDir(zipMode{0-连同目录一起压缩,1-压缩指定目录中的所有文件和文件夹}:Integer;zipControl:TVCLZip;MyZipName,MyZipDir:string):Boolean;
begin
  {压缩指定目录中的所有文件和文件夹,指定RootDir,否则连同指定目录本身一同压缩}
  Result:=False;
  try
  with zipControl do
  begin
  case zipMode of
  0:RootDir:='';
  1:RootDir:=MyZipDir;
  end;
  OverwriteMode:=Always;
  AddDirEntriesOnRecurse:=True;
  RelativePaths:=True;
  //Recurse:=True;
  //RecreateDirs:=True;
  //StorePaths:=True;
  ZipName:=MyZipName;
  FilesList.Add(MyZipDir+'\*.*');
  Zip;
  Result:=True;
  end;
  except

  end;
end;

end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值