主页 > 编程资料 > Delphi >
发布时间:2015-09-22 作者:网络 阅读:162次

VCLZip压缩解压文件支持winzip,下面给个简单调用的例子,控件在本站可以下载:

uses VCLUnZip, VCLZip;

function ComPressFile(dstFile,srcFile:string):Boolean;
var
vclzip:TVCLZip;
begin
Result:=False;
vclzip:=TVCLZip.create(nil,',',');
try
with vclzip do
begin
try
ZipName:=dstFile;
RecreateDirs:=true; //注意这里
StorePaths:=False;
FilesList.Add(srcFile,',',');
Recurse := True;
Zip;
Result:=True;
except
Application.MessageBox('压缩文件失败','错误',MB_OK+MB_ICONINFORMATION,',',');
Result:=False;
exit;
end;
end;
finally
vclzip.Free;
end;
end;

function UnComPressFile(sFile,sOutFile:string):Boolean;
var
vcluzip:TVCLUnZip;
begin
Result:=False;
vcluzip:=TVCLUnZip.Create(nil,',',');
try
with vcluzip do
begin
try
ZipName:=sFile;
ReadZip;
FilesList.Add('*.*',',',');
DoAll := False;
DestDir := sOutFile;
RecreateDirs := False;
RetainAttributes := True;
Unzip;
Result:=True;
except
Application.MessageBox('解压文件失败','错误',MB_OK+MB_ICONINFORMATION,',',');
Result:=False;
exit;
end;
end;
finally
vcluzip.Free;
end;
end;

关键字词: