#1 2016-07-12 06:16:38

Bob_AGI
Member
Registered: 2016-07-12
Posts: 4

PasZip - how to embed extract folder in zipfile

I have downloaded the PasZip.pas unit for my Delphi 2007 usage in order to store data files in a zipfile in the simplest way.
The data files I must store all pertain to a particular measurement result and comprise both binary and text files.
All works fine so far except for one item:

I need to set the path of extraction into the zipfile such that on extraction using any zip utility such as WinZip, 7Zip, WinRar etc all the zipped files get extracted into a directory below the location of the zipfile.
The name of the directory could be the name of the zipfile (without extension) or a unique dir name embedded into the zipfile, it is just important that the files are not extracted into the current dir.

I have searched for this but I only found one search result and this is another user asking here for how to embed a relative extraction path into the zip using TZipWrite. There is no reply for this question...
See here: store relative paths

I it possible to do with PasZip?

Last edited by Bob_AGI (2016-07-12 06:17:26)

Offline

#2 2016-07-12 06:21:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: PasZip - how to embed extract folder in zipfile

Just store the relative path within the file name.

Offline

#3 2016-07-12 09:25:31

Bob_AGI
Member
Registered: 2016-07-12
Posts: 4

Re: PasZip - how to embed extract folder in zipfile

I forgot to mention my use so below is the code.
Notice that the list of files are supplied in a stringlist and these contain the full path to the files to zip.
They can be located in different places on the file system but I want them to be extracted together.

function TSSCommHandler.ZipFiles(TargetFile: string; FileList: TStringList): boolean;
{This function uses the Synopse files PasZip.pas and Synopse.inc to create the zipfile.
Files were obtained from http://synopse.info/fossil/dir?ci=tip}
var
  ZW: TZipWrite;
  i: integer;
  FileName: string;
begin
  Result := false;
  ZW := TZipWrite.Create(TargetFile);
  try
    try
      for i := 0 to FileList.Count-1 do
      begin
        FileName := FileList[i];
        if not FileExists(FileName) then Continue;
        ZW.AddDeflated(FileName); //How do I add a relative path here?
      end;
      Result := true;
    except
      on E: Exception do
      begin
        FLastError := 'Zip error: ' + E.Message;
        exit;
      end;
    end;
  finally
    ZW.Free;
  end;
end;

Any ideas on where/how I should add the target extraction path (relative to zipfile)?

Offline

#4 2016-07-12 16:11:07

Bob_AGI
Member
Registered: 2016-07-12
Posts: 4

Re: PasZip - how to embed extract folder in zipfile

Just store the relative path within the file name.

With what command can I do that?
If I use a "trick" path by replacing the supplied path in the ZW.AddDeflated call then I assume that the system cannot find the fie to add into the zip...
Is there a property or similar I can use to tell the zip that the file should be extracted to say ./MyFileName?

Offline

Board footer

Powered by FluxBB