VCLZIP 使用

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;

你可能感兴趣的:(zip)