topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 5:51 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: [DISCUSSION] How to extract embedded zip/rar files recursively in one step?  (Read 19761 times)

vixay

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 140
  • ViXaY
    • View Profile
    • Donate to Member
This has been bugging me for a while...
Often when you dowload something it is compressed multiple times and is very annoying to extract.
e.g.
xx.zip
-yy1.zip
--yy1.rar
---zz.exe
-yy2.zip
--yy2.rar
---zz.exe
-yy3.zip
--yy3.rar
---zz.exe
So for the above case which shows the directory structure of xx.zip file. Now how can i extract zz.exe in one step, without having to first extract xx.zip, then all yy#.zip, then yy#.rar?

I have beel looking everywhere! Unrar can extract embedded files, but not split embedded files... don't ask me to explain, try it yourself.

anybody have any ideas/suggestions?

Actually i figured out one script that works for me
@echo OFF

SET "dir=."
SET "ext=*.zip"

winRAR x -o+ %1

FOR /r "%dir%" %%* IN (%ext%) DO (
  winRAR x -o+ "%%*" "%%~dp*"
  del "%%*"
  )

winrar x -r -o+ *.part1.rar
del /s *.part?.rar

but this works only for a specific case (i.e. where you have an archive in which you have zip files in which you have rar files)
can it be improved to work for all cases?
"Drunk on the Nectar of Life!" -me
« Last Edit: September 13, 2006, 06:57 AM by vixay »

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Allways the same structure?

Maybe with an batch.cmd:
C:\>UNPACK *.zip  INTO STEP1
CD STEP1
C:\STEP1>UNPACK *.zip INTO STEP2
CD STEP2
C:\STEP1\STEP2>UNRAR *.rar INTO STEP3
CD STEP3
C:\STEP1\STEP2\STEP3>EXTRAXT *.exe INTO STEP4
... to be continue

vixay

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 140
  • ViXaY
    • View Profile
    • Donate to Member
Actually, no. That's the whole point! I want something that works with all cases (not a specific case)
The script i provided works for a specific case of zip/rar(zip(rar)))

And i want to preserve the directory structure, and remove the intermediate files.

So let me restate my objective: Extract all archives from within an archive (passed parameter) and/or directory (i.e. recursive), while preserving directory structure and deleting intermediate files generated.

Save the following code in a batch file with the name extract3levels.cmd
@echo OFF
REM //Set up some variables
SET "dir=."
SET "ext=*.zip"

REM //Extract the passed file, to current directory
REM //overwriting files.
winRAR x -o+ %1
REM //Should have a graceful error case here to make sure the operation completed
REM //successfully, if not then exit script... how to do this?

REM //Now in the current directory extract each zip file into its folder
REM //Delete the file after extracting it
FOR /r "%dir%" %%* IN (%ext%) DO (
  winRAR x -o+ "%%*" "%%~dp*"
  del "%%*"
  )

REM //Now search for a file ending with part1.rar in all subdirectories and extract it
winrar x -r -o+ *.part1.rar
REM //Delete all files ending with a part?.rar in all subdirectories
del /s *.part?.rar

REM Usage:
REM program_name <archive>

 the above script works, but maybe what i want needs a more flexible language, maybe autohotkey can do this...?
"Drunk on the Nectar of Life!" -me
« Last Edit: September 14, 2006, 02:06 AM by vixay »

Cloq

  • Charter Member
  • Joined in 2006
  • ***
  • default avatar
  • Posts: 282
    • View Profile
    • Donate to Member
Hmm.. Total Commander handles that for me. Since it "opens" archives as directories/folders, all you have to do is keep pressing enter/clicking on it till you get to the actual file. Then you can drag/copy it out to the desktop (or wherever) or to the other windowpane. So far I have tested with multi-level combinations of zips and rars nest in each other, 6 archive deep.

vixay

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 140
  • ViXaY
    • View Profile
    • Donate to Member
Hmm.. Total Commander handles that for me. Since it "opens" archives as directories/folders, all you have to do is keep pressing enter/clicking on it till you get to the actual file. Then you can drag/copy it out to the desktop (or wherever) or to the other windowpane. So far I have tested with multi-level combinations of zips and rars nest in each other, 6 archive deep.

That's ok. Even winrar can do that. with only 1 archive embeded (no matter how many levels) it is ok to do this, but what about when you have 5 archives in 1 archive, and then in those 5 archives you have 1 archive each, but that 1 archive is a split archive... so to extract the files, you need to get all those 5 archives hidden within each of those split archives and then extract them.. sigh, i guess i am not making much sense, let me see if i can whip up a sample for you...

"Drunk on the Nectar of Life!" -me

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
How often do you actually encounter stuff like this? I've no doubt its very annoying but it must be very rare, and isn't it illogical as solid archiving would achieve better compression than this sort of nested archiving.

That said though I don't know of any program to help you, sorry.

vixay

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 140
  • ViXaY
    • View Profile
    • Donate to Member
How often do you actually encounter stuff like this? I've no doubt its very annoying but it must be very rare, and isn't it illogical as solid archiving would achieve better compression than this sort of nested archiving.

That said though I don't know of any program to help you, sorry.

No problem! Thanks anyway.
I was just trying to plumb the intellect of the donationcoder community to figure out if there was a better way to do this other than what I've found so far. (which i am sure there is)
Obsessed with making things easy & simple, and a programmer, i figured there oughta be a way.
As for frequency, you are right it isn't that often, maybe once or twice a week. No doubt the logic is unfathomable, regardless that is what one recieves and one has to try and improve where one can.

Anyway thinking of all this has made me think that maybe i ought to write the psuedocode and maybe that will help explain what i need.

Examine passed file/directory
Process each file
 if not archive, skip //base case, exit condition
 elseif archive
   extract all files with path into a subdir $temp$, overwriting existing files
   set flag $extracted$
if flag $extracted$
  call self with $temp$ //recursive call
  delete archive(s) in $temp$ //remove temp archives as they should be extracted by now

// there should probably be some ending code to move extracted files from $temp$ to directory of the orginal archive

I forget if this is an in-order, pre-order, or post-order traversal recursive algorithm http://en.wikipedia.org/wiki/Tree_search. But i think that should do the trick. Though, the important thing is to extract all level 1s first, then process the next level, as only then will split archives be handled appropriately.
"Drunk on the Nectar of Life!" -me
« Last Edit: September 15, 2006, 06:58 AM by vixay »

Cloq

  • Charter Member
  • Joined in 2006
  • ***
  • default avatar
  • Posts: 282
    • View Profile
    • Donate to Member
That's ok. Even winrar can do that. with only 1 archive embeded (no matter how many levels) it is ok to do this, but what about when you have 5 archives in 1 archive, and then in those 5 archives you have 1 archive each, but that 1 archive is a split archive... so to extract the files, you need to get all those 5 archives hidden within each of those split archives and then extract them.. sigh, i guess i am not making much sense, let me see if i can whip up a sample for you...

Would you be able to upload a sample archive (filled with dummy text archives) with the above mentioned structure with it?

vixay

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 140
  • ViXaY
    • View Profile
    • Donate to Member
That's ok. Even winrar can do that. with only 1 archive embeded (no matter how many levels) it is ok to do this, but what about when you have 5 archives in 1 archive, and then in those 5 archives you have 1 archive each, but that 1 archive is a split archive... so to extract the files, you need to get all those 5 archives hidden within each of those split archives and then extract them.. sigh, i guess i am not making much sense, let me see if i can whip up a sample for you...

Would you be able to upload a sample archive (filled with dummy text archives) with the above mentioned structure with it?

Here ya go! Some random text file...
"Drunk on the Nectar of Life!" -me

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
vixay:
from the structure you presented, it seems that you need a tool like Rarslave or other similar Usenet binary tools.

vixay

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 140
  • ViXaY
    • View Profile
    • Donate to Member
vixay:
from the structure you presented, it seems that you need a tool like Rarslave or other similar Usenet binary tools.

Hmm... didn't work out with the test archive... i guess it ignores it because its a zip.... even after disabling the RAR only flag it doesnt' work...
"Drunk on the Nectar of Life!" -me

wr975

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 369
    • View Profile
    • Donate to Member

I wrote a AHK script for myself once + integrated it in 2xplorer. So I just click a button and all archives in the folder get unpacked. Perhaps it's of use for you? It unpacks all archives in a folder in a subfolder (archive-name).

Installation: paste code in notepad, edit the second line pointing to winrar.exe, save as whatever.ahk, install authotkey (autohotkey.com)

Usage: Copy sourcefolder in clipboard and launch the script, or pass the sourcefolder as first parameter. An optional second parameter would be a targetfolder (where to place unpacked files).

Limitation: Some (rare) RAR names makes it to mess up. Didn't figure that out yet.


AHK Code:
Spoiler
#SingleInstance force
winrar = C:\progs\system\winrar\winrar.exe

eins = %1%
zwei = %2%

If 1 =
   Target = %Clipboard%
else
   Target = %1%

IfNotExist,%Target%
   {
   MsgBox,No parameters given:`n`n#1 = Sourcefolder`n#2 = Targetfolder (optional, else it'll unpack in SourceFolder)
   ExitApp
   }


Loop,%target%\*.*
   {
   SplitPath,A_LoopFileFullPath,UnpackFileName,UnpackPath,UnpackExtension,Unpackname

   If UnpackExtension = zip
      {
      StringLen,UnpackLaenge,UnpackName
      UnpackLaengeMinus := UnpackLaenge - 2
      StringMid,UnpackDatei,UnpackName,1,%UnpackLaengeMinus%
      Unpack(A_LoopFileLongPath,UnpackPath,UnpackDatei,eins,zwei)
      Continue
      }

   If UnpackExtension = 001
      {
      Unpack(A_LoopFileLongPath,UnpackPath,UnpackName,eins,zwei)
      Continue
      }

   If UnpackExtension = rar
      {
      If Unpackname contains .part
         {
         StringLen,UnpackLaenge,UnpackName
         if UnpackFileName contains .part1.
            {
            UnpackLaengeMinus := UnpackLaenge - 5
            StringMid,UnpackDatei,UnpackName,1,%UnpackLaengeMinus%
            Unpack(A_LoopFileLongPath,UnpackPath,UnpackDatei,eins,zwei)
            }

         if UnpackFileName contains .part01.
            {
            UnpackLaengeMinus := UnpackLaenge - 6
            StringMid,UnpackDatei,UnpackName,1,%UnpackLaengeMinus%
            Unpack(A_LoopFileLongPath,UnpackPath,UnpackDatei,eins,zwei)
            }

         if UnpackFileName contains .part001.
            {
            UnpackLaengeMinus := UnpackLaenge - 7
            StringMid,UnpackDatei,UnpackName,1,%UnpackLaengeMinus%
            Unpack(A_LoopFileLongPath,UnpackPath,UnpackDatei,eins,zwei)
            }

         if UnpackFileName contains .part0001.
            {
            StringLen,UnpackLaenge,UnpackName
            UnpackLaengeMinus := UnpackLaenge - 8
            StringMid,UnpackDatei,UnpackName,1,%UnpackLaengeMinus%
            Unpack(A_LoopFileLongPath,UnpackPath,UnpackDatei,eins,zwei)
            }
         Continue
         }         
      Unpack(A_LoopFileLongPath,UnpackPath,Unpackname,eins,zwei)
      Continue
      }
   }

ExitApp


Unpack(source,target,name,eins,zwei)
{
if zwei =
      RunWait,%winrar% x -o+ "%source%" "%target%\%name%\"
else
      RunWait,%winrar% x -o+ "%source%" "%zwei%\%name%\"
}