Recent

Author Topic: Zip File, Extract folder and subfolders  (Read 12129 times)

anis2505

  • Full Member
  • ***
  • Posts: 201
Zip File, Extract folder and subfolders
« on: February 12, 2016, 09:09:22 am »
Hi there,

So I need help to extract a folder and its subfolders from a zip file.
I used abbrevia but I does not extract the subfolders

Any Idea how to do this using any component and with a password proteced zip file

thanks in advance
Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Zip File, Extract folder and subfolders
« Reply #1 on: February 12, 2016, 09:58:02 am »
I used abbrevia but I does not extract the subfolders
Are you sure Abbrevia does not extract folders???
Are you using the correct options?
Did you specify the correct ExtractOptions for unzipping?
Code: Pascal  [Select][+][-]
  1. UnZip.ExtractOptions := [eoCreateDirs, eoRestorePath];

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Zip File, Extract folder and subfolders
« Reply #2 on: February 17, 2016, 12:28:17 am »
I did these options but still don't extract its subfolders :(
Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Zip File, Extract folder and subfolders
« Reply #3 on: February 17, 2016, 09:11:59 am »
Maybe it could help if you showed us your exact code.

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Zip File, Extract folder and subfolders
« Reply #4 on: February 17, 2016, 01:39:59 pm »
Hi,

I was very busy lately, thus I got confused between multiple threads with same issue.

Code: Pascal  [Select][+][-]
  1. AbUnZipper.ExtractOptions:= [eoCreateDirs,eoRestorePath];
  2. AbUnZipperTasks.ExtractFiles(FolderPath+'\*.*');
  3.  
Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Zip File, Extract folder and subfolders
« Reply #5 on: February 17, 2016, 02:01:40 pm »
This can't be the COMPLETE code your using. Just quoting two lines isn't much help.
But I'll give it a shot...
Why are you setting the Extract options of AbUnzipper but are using another component for extracting??? (AbUnzipperTasks ??)
You need to set the ExtractOptions of the component you're using to extract.

Another problem. You're using FolderPath+'\*.*' as ExtractWildcard. Is the path FolderPath completely present in your zip? Normally you would just do '*.*' of 'folder\*.*' If FolderPath also contains a driveletter (i.e. 'C:\Folder\') and the zip does not... nothing will be extracted.

So:
Code: Pascal  [Select][+][-]
  1. AbUnZipperTasks.ExtractOptions:= [eoCreateDirs,eoRestorePath]; // <-- same component as for ExtractFiles !!
  2. AbUnZipperTasks.ExtractFiles('\*.*');
Or
Code: Pascal  [Select][+][-]
  1. AbUnZipperTasks.ExtractOptions:= [eoCreateDirs,eoRestorePath];
  2. AbUnZipperTasks.ExtractFiles(PathWithoutDrive+'\*.*');
(and make sure PathWithoutDrive only contains the relative path which is present in the zip)

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Zip File, Extract folder and subfolders
« Reply #6 on: February 18, 2016, 02:55:22 pm »
Hi,

I'm sorry for late answer,
It's the same component I forgot to rename it for the post.

Can you please explain what do you mean by PathWithoutDrive
It's a compressed folder how would it contain drive
Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Zip File, Extract folder and subfolders
« Reply #7 on: February 18, 2016, 03:06:34 pm »
Can you please explain what do you mean by PathWithoutDrive
It's a compressed folder how would it contain drive
No, your zip won't contain a drive but it does contain relative folders.

Could you state what value FolderPath had when it comes to that part of your code?
And if FolderPath contains just the name 'folder' it should work (I tried it).

So try setting a Showmessage(FolderPath) just before the ExtractFiles and post it's value here.

(Also if Folderpath had \ in front it, it won't work either.)

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Zip File, Extract folder and subfolders
« Reply #8 on: February 18, 2016, 03:22:23 pm »
Hi,
See the attached it's the folder content
now It does extract the folder and the 2 subfolders but they are all empty.

Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Zip File, Extract folder and subfolders
« Reply #9 on: February 18, 2016, 03:25:42 pm »
Just to be clear... is your FolderPath that path or is what you showed the complete string you pass to ExtractFiles?
( not that you're passing folder\*.*\*.* )

And what happens if you just do ExtractFiles('*.*') ??

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Zip File, Extract folder and subfolders
« Reply #10 on: February 18, 2016, 03:39:57 pm »
Just to be clear... is your FolderPath that path or is what you showed the complete string you pass to ExtractFiles?
( not that you're passing folder\*.*\*.* )

With \*.*\*.* nothing is extracted even empty folders


And what happens if you just do ExtractFiles('*.*') ??
It does extract all files in the entire archive

Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Zip File, Extract folder and subfolders
« Reply #11 on: February 18, 2016, 03:49:48 pm »
I tried it with AbUnZipperTasks.ExtractFiles('synapse\*.*'); on a backup I have of a zip with multiple folders (of which synapse is one). It extracted only the synapse folder to the BaseDirectory i set. So it worked perfectly here.

Maybe it's time to create a small test-project which you can post here with a small test-zip that isn't working for you.

For example, this is my test-version:
Code: Pascal  [Select][+][-]
  1. uses AbUnzper, AbArcTyp;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.   AbUnZipper: TAbUnzipper;
  6. begin
  7.   AbUnZipper := TAbUnzipper.Create(nil);
  8.   try
  9.     ForceDirectories('c:\temp\t3');
  10.     AbUnZipper.BaseDirectory := 'c:\temp\t3';
  11.     AbUnZipper.FileName := 'c:\temp\my_backup_file.zip';
  12.     AbUnZipper.ExtractOptions := [eoCreateDirs, eoRestorePath];
  13.     AbUnZipper.ExtractFiles('synapse\*.*');
  14.     ShowMessage('done');
  15.   finally
  16.     AbUnZipper.Free;
  17.   end;
  18. end;
  19.  


EDIT: Correction. You're correct. When supplying a subfolder, ONLY the direct files within that subfolder are extracted. Not sub-subfolders and its files.
« Last Edit: February 18, 2016, 04:07:47 pm by rvk »

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Zip File, Extract folder and subfolders
« Reply #12 on: February 18, 2016, 04:18:04 pm »
Hi,

Here is a sample
I'm using CodeTyphon with their AbTreeview

Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Zip File, Extract folder and subfolders
« Reply #13 on: February 18, 2016, 04:28:52 pm »
Here is a sample
Yeah, I just tested another archive with sub-sub-folders and also noticed that only the files in the directory itself are extracted and not the subdirectories. It's probably because the FileMask doesn't match the sub-folders.

Not sure what to do about it at this point.
You could use the tag-system to tag all the files that need to be extracted. Or extract to a temporary-directory and only use that subdir. But yeah, it would have been easier if Abbrevia dismembered that FileMask if it hit a subfolder and could extract all subfolders accordingly.

anis2505

  • Full Member
  • ***
  • Posts: 201
Re: Zip File, Extract folder and subfolders
« Reply #14 on: February 18, 2016, 04:34:39 pm »

You could use the tag-system to tag all the files that need to be extracted. Or extract to a temporary-directory and only use that subdir. But yeah, it would have been easier if Abbrevia dismembered that FileMask if it hit a subfolder and could extract all subfolders accordingly.


Yes this is what I'm trying to do now.

I will see if it's gonna work

Thanks for everything :)
Dear Confucius you said {A picture is worth a thousand words}
I say {a good example is worth a thousand words}

 

TinyPortal © 2005-2018