谁能马上给各vclzip压缩和解压的例子!一个listbox放带压缩文件路径
edit.text放还没创建的*.zip

解决方案 »

  1.   

    VCLZip 本身就有Demo吧-_-! 你就不能改改??
      

  2.   

    压缩:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      sp:tsavedialog;  savefilename : String;
      op:topendialog; i:integer;
    begin
      Memo1.Lines.Clear;  op:=topendialog.Create(nil);
      op.Options:=[ofAllowMultiSelect,ofReadOnly,ofPathMustExist, ofFileMustExist];
      op.Execute;
      if op.FileName<> '' then
         for i:= 0 to Op.Files.Count-1 do
             Memo1.Lines.Add(Op.Files.Strings[i]);  op.Free;
      sp:=tsavedialog.Create(nil);
      sp.Filter:='Zip file|*.Zip';
      sp.DefaultExt:='Zip';
      sp.FileName := 'C:\Install';         //默认压缩的文件路径
      try
        if (sp.Execute) and (sp.FileName<>'') then savefilename:=sp.FileName else Abort;
      finally
        sp.Free;
      end;
      
     With VCLZip1 do
      begin
        ZipName := savefilename;
        Password := 'test';
        //ZipName := 'C:\BACKUP.ZIP';
      //  MultiZipInfo.MultiMode := mmBlocks;
      //  MultiZipInfo.FirstBlockSize := 700000;
     //   MultiZipInfo.BlockSize := 1457600;
       for i := 0 to Memo1.Lines.Count -1 do
        FilesList.Add(Memo1.Lines[i]);
        Recurse := True;       
        Zip;
      end;              
    end;解压缩:
    procedure TForm1.Button2Click(Sender: TObject);
    var
      i : integer;
      NumUnzipped : Integer;
      sp:tsavedialog;  savefilename : String;  openfilename : string;
      op:topendialog;
    begin
      op:=topendialog.Create(nil);
      op.Options:=[ofAllowMultiSelect,ofReadOnly,ofPathMustExist, ofFileMustExist];
      if (op.Execute) and (op.FileName<>'') then openfilename:=op.FileName else Abort;
             
      With VCLUnZip1 do
      begin
        Memo1.Lines.Clear;    ZipName := openfilename;
        Password := 'test';
      //  ZipName := 'C:\BACKUP.ZIP';    // set the zip filename
        ReadZip;                           // open it and read its information    // List filenames in zip file    for i := 0 to Count-1 do    Memo1.Lines.Add( Filename[i] + #9 + Pathname[i] );    // extract some files    // determine which files to unzip{    FilesList.Add( '*.cpp' );                    // unzip all .cpp files
        FilesList.Add( 'myprog.exe' );               // unzip myprog.exe
        FilesList.Add( '?<0-9>*\*.h' );              // .h files, if 2nd letter of dir starts with digit only
        FilesList.Add( Filename[Count-1] );          // extract last entry in zipfile
     }
        DoAll := True;                              // Don't unzip all files    DestDir := 'D:\test';                        // Set destination directory
        RecreateDirs := True;                       // don't recreate directory structures
        RetainAttributes := True;                    // Set attributes to original after unzipping    NumUnzipped := Unzip;                        // Extract files, return value is the number of files actually unzipped  end;  showmessage(inttostr(NumUnzipped));
    end;