EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ZIP Writer - zipping of files in directory tree

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#13521
Posted: 05/29/2010 10:25:06
by kmartinka (Standard support level)
Joined: 05/29/2010
Posts: 2

Hello,

I want to know, if there is a way, how to omit the initial directory name when compressing the whole directory tree.

Code
ElZipWriter1.CreateArchive;
ElZipWriter1.Add('c:\Directory\');
ElZipWriter1.Compress('c:\test.zip');


This code will produce a ZIP file with all files in the c:\Directory, however it will be placed in \directory\ subdir inside the ZIP. Is there any way to put the contents of C:\Directory in to the root of ZIP file (incl. the subdirectories of Directory, recursively), execept doing it manually using findfirst/findnext, please?

Thanks
Karol
#13522
Posted: 05/29/2010 11:14:23
by Eugene Mayevski (EldoS Corp.)

From documentation it seems that there's no way to specify how to store the "root" folder. One of the reasons is that you might want to call Add('c:\Directory\') and Add('d:\Directory2') before calling Compress(), and the application doesn't know this until the call to Compress. We will add an optional parameter to Add, which will specify what to do with the path.


Sincerely yours
Eugene Mayevski
#13523
Posted: 05/29/2010 11:35:52
by kmartinka (Standard support level)
Joined: 05/29/2010
Posts: 2

Thanks, it will help me a lot. When do you expect to have it?

I've already did the workaround using FindFirst/FindNext, hope that it will work for all cases :)

Here it is :

Code
procedure ZipWholeDir(Path: string; zipWrtr: TElZipWriter);
var
  SR: TSearchRec;
begin
  Path:=ExcludeTrailingBackslash(Path)+'\';
  if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
  begin
    repeat
      if (SR.Attr <> faDirectory) then
      begin
        zipWrtr.Add(Path+sr.name);
      end
       else
        if (sr.name<>'.') and (sr.name<>'..') then
           zipWrtr.Add(Path+sr.name+'\');
    until FindNext(SR) <> 0;
    FindClose(SR);
  end;
end;


Karol
#13524
Posted: 05/29/2010 12:04:14
by Eugene Mayevski (EldoS Corp.)

We plan new build for second half of June.


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 1857 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!