现在的位置: 首页 > 综合 > 正文

VCLZIP 使用

2012年12月21日 ⁄ 综合 ⁄ 共 788字 ⁄ 字号 评论关闭
function ComPressFile(dstFile,srcFile:string):Boolean;
var
  vclzip:TVCLZip;
begin
  Result:=False;
  vclzip:=TVCLZip.create(nil);
  try
    with vclzip do
    begin
      try
        ZipName:=dstFile;
        RecreateDirs:=true; //注意这里
        StorePaths:=False;
        FilesList.Add(srcFile);
        Recurse := True;
        Zip;
        Result:=True;
      except
        Application.MessageBox('压缩文件失败','错误',MB_OK+MB_ICONINFORMATION);
        Result:=False;
        exit;
      end;
    end;
  finally
    vclzip.Free;
  end;
end;

function UnComPressFile(sFile,sOutFile:string):Boolean;
var
  vcluzip:TVCLUnZip;
begin
  Result:=False;
  vcluzip:=TVCLUnZip.Create(nil);
  try
    with vcluzip do
    begin
      try
        ZipName:=sFile;
        ReadZip;
        FilesList.Add('*.*');
        DoAll := False;
        DestDir := sOutFile;
        RecreateDirs := False;
        RetainAttributes := True;
        Unzip;
        Result:=True;
      except
        Application.MessageBox('解压文件失败','错误',MB_OK+MB_ICONINFORMATION);
        Result:=False;
        exit;
      end;
    end;
  finally
    vcluzip.Free;
  end;
end;

抱歉!评论已关闭.