查来查去! 好象只能对文件进行压缩.
现在我的要求是对某个文件夹下的所有文件进行压缩,
说白了就是象WinRaR 那样的效果! 我点选那个目录就压缩
那个目录, 解压出来跟压缩前的目录一样.
现在我的要求是对某个文件夹下的所有文件进行压缩,
说白了就是象WinRaR 那样的效果! 我点选那个目录就压缩
那个目录, 解压出来跟压缩前的目录一样.
解决方案 »
- 关于Delphi DLL动态连接库编写与调用的问题
- 如何实现TIFF图片格式转化为DJVU图片格式
- 在FASTREPORT3.07中怎么样在程序里设置纸张类型?谢谢!
- 在DELPHI中可不可以做自由做表。
- 关于消息窗口的函数
- 求教:点击后弹出提示框
- ADOQuery中使用过Filter后,如何恢复原来的数据集?(Filter:=''就行吗?)
- 50分寻求一条汇总统计的SQL语句!------关于分类统计工资总额的问题
- 用InstallShield Express For Delphi 5打包怎么设置BDE
- 要做一个类似文本编译器的东西,用哪一个控件比较方便,edit or memo or others
- 当有人向文件服务器上传文件时,服务器向局域网内相应的工作站发送即时消息。哪位朋友有这方面的资料或心得,希望给点提示。
- cxgrid里如何通过代码,根据不同条件,控制同一列的不同行的可编辑属性,也就是Editing,Readonly属性
或者还有什么好办法! 还有这些目录和文件名称和扩展名称应该怎么处理为好>>.
Author: Robert Kuhlmann
uses
Zlib; procedure CompressFiles(Files : TStrings; const 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-1 do
begin
infile := TFileStream.Create(Files[i],fmOpenRead);
try
{ the original filename }
s := ExtractFilename(Files[i]);
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; procedure DecompressFiles(const Filename, DestDirectory : String);
var
dest,s : String;
decompr : TDecompressionStream;
infile, outfile : TFilestream;
i,l,c : Integer;
begin
// IncludeTrailingPathDelimiter (D6/D7 only)
dest := IncludeTrailingPathDelimiter(DestDirectory); infile := TFileStream.Create(Filename,fmOpenRead);
try
{ number of files }
infile.Read(c,SizeOf(c));
for i := 1 to c do
begin
{ read filename }
infile.Read(l,SizeOf(l));
SetLength(s,l);
infile.Read(s[1],l);
{ read filesize }
infile.Read(l,SizeOf(l));
{ decompress the files and store it }
s := dest+s; //include the path
outfile := TFileStream.Create(s,fmCreate);
decompr := TDecompressionStream.Create(infile);
try
outfile.CopyFrom(decompr,l);
finally
outfile.Free;
decompr.Free;
end;
end;
finally
infile.Free;
end;
end;