通过挖掘 ExtractFilesEx 函数找到的解决方案。只需使用该集合FArchive
并检查其属性即可。
使用更底层的函数ExtractAt
procedure unzipFiles;
var
zp : TAbZipKit;
i : integer;
begin
//
zp := TAbZipKit.Create(nil);
zp.OpenArchive(StartDir + '\zipfile.zip');
zp.BaseDirectory := StartDir;
zp.ExtractOptions := [eoCreateDirs, eoRestorePath];
// ------- new
// examine if there is a / in the StoredPath property
// if blank, it's in the root.
for i := 0 to zp.FArchive.Count -1 do
begin
if (zp.FArchive.ItemList.Items[i].StoredPath <> '') then
begin
zp.ExtractAt(i, '');
end;
end;
(*
zp.ExtractFilesEx(
includepath,
excludepath
);
*)
zp.CloseArchive;
zp.Free;
end;
根据 Peter Wolff,使用 OnEvent 处理的解决方案
为此,必须将一个类添加到代码中。
// add these to the USES directive
uses
AbBase, AbArcTyp, AbZipKit, Abutils;
// now add a class
type
zip_helper = class
public
procedure ZipConfirmProcessItem(
Sender: TObject;
Item: TAbArchiveItem;
ProcessType: TAbProcessType;
var Confirm: Boolean);
end;
// the class helper function could be like this:
procedure zip_helper.ZipConfirmProcessItem(
Sender: TObject;
Item: TAbArchiveItem;
ProcessType: TAbProcessType;
var Confirm: Boolean);
begin
Confirm := (Item.StoredPath <> '');
end;
// Now the extract from above can be changed to this:
procedure unzipDefaults;
var
zp : TAbZipKit; // our zipper
hlp: zip_helper; // class helper
begin
zp := nil;
hlp := nil;
try
hlp := zip_helper.create; // create the class helper
zp := TAbZipKit.Create(nil);
zp.OpenArchive(StartDir + '\Defaults.zip');
zp.BaseDirectory := StartDir;
zp.ExtractOptions := [eoCreateDirs, eoRestorePath];
// set the event
//
zp.OnConfirmProcessItem := hlp.ZipConfirmProcessItem;
// and simply extract all
zp.ExtractFiles('*.*');
zp.CloseArchive;
finally
FreeAndNil(zp);
freeandnil(hlp);
end;
end;