1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| | unit uVclZipPublic;
interface
uses SysUtils, Variants, Classes,VCLZip,VCLUnZip;
function ZipFiles(zipControl:TVCLZip;Files:TStrings;MyZipName:string):Boolean;
function UnZipFiles(zipControl:TVCLZip;MyZipName,MyDestDir:string):Boolean;
function ZipDir(zipMode{0-连同根目录一起压缩,1-压缩指定目录中的所有文件和文件夹}:Integer;zipControl:TVCLZip;MyZipName,MyZipDir:string):Boolean;
implementation
function ZipFiles(ZipControl:TVCLZip;Files:TStrings;MyZipName:string):Boolean;
begin
Result:=False;
try
with ZipControl do
begin
FilesList.Text:=Files.Text;
ZipName:=MyZipName;
Zip;
Result:=True;
end;
except
//Showmessage('');
end;
end;
function UnZipFiles(zipControl:TVCLZip;MyZipName,MyDestDir:string):Boolean;
begin
Result:=False;
try
with zipControl do
begin
ZipName:=MyZipName;
ReadZip;
DestDir:=MyDestDir;
OverwriteMode:=Always;
RelativePaths:=True;
RecreateDirs:=True;
DoAll:=True;
FilesList.Add('*.*');
UnZip;
Result:=True;
end;
except
end;
end;
function ZipDir(zipMode{0-连同目录一起压缩,1-压缩指定目录中的所有文件和文件夹}:Integer;zipControl:TVCLZip;MyZipName,MyZipDir:string):Boolean;
begin
{压缩指定目录中的所有文件和文件夹,指定RootDir,否则连同指定目录本身一同压缩}
Result:=False;
try
with zipControl do
begin
case zipMode of
0:RootDir:='';
1:RootDir:=MyZipDir;
end;
OverwriteMode:=Always;
AddDirEntriesOnRecurse:=True;
RelativePaths:=True;
//Recurse:=True;
//RecreateDirs:=True;
//StorePaths:=True;
ZipName:=MyZipName;
FilesList.Add(MyZipDir+'\*.*');
Zip;
Result:=True;
end;
except
end;
end;
end. |