1.如何用Delphi命令将c:\cxj.txt压缩成c:\cxj.zip?2.如何用Delphi命令将c:\cxj.zip还原成c:\cxj.txt?

解决方案 »

  1.   

    ZIP,UPZIP控件網上應該很多
    找找看吧
      

  2.   

    使用unzip,然后通过命令行就可以了
    shellexecute('unzip * *')
    呵呵,试试吧!我没有亲自体验
      

  3.   

    用vclzip控件
    ZipName := ExtractFileDir(Application.Exename)+'*.zip';    // set the zipfile filename
      ReadZip;  // open it and read its information
      DoAll := true;   // unzip all files
      OverwriteMode := Always; //always replace
      DestDir := ExtractFileDir(Application.Exename)+'\dtemp';  // Set destination directory
      RecreateDirs := False;     // don't recreate directory structures
      RetainAttributes := True;   // Set attributes to original after unzipping很好用的哦!
    搜索vclzip就行了,有d5d6的!
      

  4.   

    ZLib压缩    
      uses 
    ZLib;{ Compress a stream }procedure CompressStream(inpStream, outStream: TStream);varInpBuf, OutBuf: Pointer;InpBytes, OutBytes: Integer;beginInpBuf := nil;OutBuf := nil;tryGetMem(InpBuf, inpStream.Size);inpStream.Position := 0;InpBytes := inpStream.Read(InpBuf^, inpStream.Size);CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes);outStream.Write(OutBuf^, OutBytes);finallyif InpBuf <> nil then FreeMem(InpBuf);if OutBuf <> nil then FreeMem(OutBuf);end;end; { Decompress a stream }procedure DecompressStream(inpStream, outStream: TStream);varInpBuf, OutBuf: Pointer;OutBytes, sz: Integer;beginInpBuf := nil;OutBuf := nil;sz := inpStream.Size - inpStream.Position;if sz > 0 thentryGetMem(InpBuf, sz);inpStream.Read(InpBuf^, sz);DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes);outStream.Write(OutBuf^, OutBytes);finallyif InpBuf <> nil then FreeMem(InpBuf);if OutBuf <> nil then FreeMem(OutBuf);end;outStream.Position := 0;end; {Example:Compress the contents of RichEdit1 andcalculate the compression rate.Then save the stream to a file (ms2.dat)Beispiel:Komprimiert den Inhalt von RichEdit1 undberechnet die Kompressionsrate.Dann wird der Stream in eine Datei (ms2.dat) gespeichert.}procedure TForm1.Button1Click(Sender: TObject);varms1, ms2: TMemoryStream;beginms1 := TMemoryStream.Create;tryms2 := TMemoryStream.Create;tryRichEdit1.Lines.SaveToStream(ms1);CompressStream(ms1, ms2);ShowMessage(Format('Stream Compression Rate: %d %%',[round(100 / ms1.Size * ms2.Size)]));ms2.SaveToFile('C:.dat');finallyms1.Free;end;finallyms2.Free;end;end;{Loads the stream from a file (ms2.dat)and decompresses it.Then loads the Stream to RichEdit1.L?dt den komprimierten Stream von einer Datei (ms2.dat)und dekomprimiert ihn.Dann wird der Stream wieder in RichEdit1 geladen.}procedure TForm1.Button2Click(Sender: TObject);varms1, ms2: TMemoryStream;beginms1 := TMemoryStream.Create;tryms2 := TMemoryStream.Create;tryms1.LoadFromFile('C:.dat');DecompressStream(ms1, ms2);RichEdit1.Lines.LoadFromStream(ms2);finallyms1.Free;end;finallyms2.Free;end;end;**********************************procedure Compress(var CompressedStream: TMemoryStream);varSourceStream: TCompressionStream;DestStream: TMemoryStream;Count: Integer;BeginCount := CompressedStream.Size;DestStream := TMemoryStream.Create;SourceStream:=TCompressionStream.Create(clMax, DestStream);TryCompressedStream.SaveToStream(SourceStream);SourceStream.Free;CompressedStream.Clear;CompressedStream.WriteBuffer(Count, SizeOf(Count));CompressedStream.CopyFrom(DestStream, 0);finallyDestStream.Free;end;end;procedure UnCompress(const CompressedStream: TMemoryStream);varSourceStream: TDecompressionStream;DestStream: TMemoryStream;Buffer: PChar;Count: integer;BeginCompressedStream.Seek(0,soFromBeginning);CompressedStream.ReadBuffer(Count, SizeOf(Count));GetMem(Buffer, Count);DestStream := TMemoryStream.Create;SourceStream := TDecompressionStream.Create(CompressedStream);TrySourceStream.ReadBuffer(Buffer^, Count);DestStream.WriteBuffer(Buffer^, Count);DestStream.Position := 0;//复位流指针CompressedStream.LoadFromStream(DestStream);finallyFreeMem(Buffer);DestStream.Free;end;end;