文件压缩和解压(50分)

  • 主题发起人 主题发起人 自由自在
  • 开始时间 开始时间

自由自在

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在程序中实现多个文件的压缩,压缩后的文件不要带目录,用哪个控件好?
给demo的送50分,只说控件名的不给分
 
呵呵,帮顶给不给分啊
 
http://www.delphibox.com/article.asp?articleid=2047

自己下载看吧.

我不要分^^
 
uses Zlib;

procedure CompressFiles(Files: TStrings;
Filename: String);
var
infile, outfile, tmpFile : TFileStream;
compr : TCompressionStream;
i,l : Integer;
s : String;
begin

if Files.Count > 0 then

begin

outFile := TFileStream.Create(Filename,fmCreate);
try
{ the number of files }
l := Files.Count;
outfile.Write(l,SizeOf(l));
for i := 0 to Files.Count-1do

begin

infile := TFileStream.Create(Files, fmOpenRead);
try
{ the original filename }
s := ExtractFilename(Files);
l := Length(s);
outfile.Write(l,SizeOf(l));
outfile.Write(s[1],l);
{ the original filesize }
l := infile.Size;
outfile.Write(l,SizeOf(l));
{ compress and store the file temporary}
tmpFile := TFileStream.Create('tmp',fmCreate);
compr := TCompressionStream.Create(clMax,tmpfile);
try
compr.CopyFrom(infile,l);
finally
compr.Free;
tmpFile.Free;
end;

{ append the compressed file to the destination file }
tmpFile := TFileStream.Create('tmp',fmOpenRead);
try
outfile.CopyFrom(tmpFile,0);
finally
tmpFile.Free;
end;

finally
infile.Free;
end;

end;

finally
outfile.Free;
end;

DeleteFile('tmp');
end;

end;
 
后退
顶部