VCLZip 压缩整个文件夹(包括子文件夹)


function ZipFile(srcFile, dstFile: string):Boolean;            //压缩单个文件
  var
    VCLZip: TVCLZip;
  begin
    Result := False;
    VCLZip := TVCLZip.create(nil);
    if srcFile[Length(srcFile)] <> '\' then srcFile := srcFile + '\';

    try
      with VCLZip do
      begin
        try
          ZipName := dstFile;
          RecreateDirs := True;
          StorePaths := False;
          FilesList.Add(srcFile + '*.*');
          Recurse := True;
          Zip;
          Result := True;
        except
          Result := False;
          exit;
        end;
      end;
    finally
      VCLZip.Free;
    end;
  end;

function UnZipFile(srcFile, dstFile: string):Boolean;
  var
    VCLZip: TVCLZip;
  begin
    Result := False;
    VCLZip := TVCLZip.create(nil);
    if dstFile[Length(dstFile)] <> '\' then dstFile := dstFile + '\';

    try
      with VCLZip do begin
        ZipName := srcFile;
        DestDir := dstFile;
        FilesList.Add('*.*');
        DoAll := True;
        Recurse := True;
        StorePaths  := True;
        UnZip;
        Result  := True
      end;
    except
      Result  := False;
    end;

    VCLZip.Free;
  end;

function ZipDir(ZipPatch,UnZipPath:string):Boolean;            //压缩文件包括子文件;
  var
    Ziper :TVCLZip;
  begin
    Ziper := TVCLZip.Create(Application);
    if UnZipPath[Length(UnZipPath)] = '\' then UnZipPath := Copy(UnZipPath,1,Length(UnZipPath)-1);

    try
      With Ziper do begin
        IncludeHiddenFiles:=true;
        IncludeSysFiles:=true;
        IncludeReadOnlyFiles:=true;
        IncludeArchiveFiles:=true;
        ZipName := ZipPatch ;
       // MultiZipInfo.MultiMode := mmBlocks  ;
        MultiZipInfo.FirstBlockSize := 700000;
        MultiZipInfo.BlockSize := 1457600;
        FilesList.Add( UnZipPath + '\*.*');
        Recurse := True;
        RelativePaths := True;
        RootDir := UnZipPath;
        Zip;
      end;
      Result := True;
    except
      Result:= False;
    end;

    Ziper.Free;
  end;

posted @ 2011-11-26 06:36  唯一的事  阅读(1548)  评论(0编辑  收藏  举报