Extract all files in subfolders

  • Anonymous - 2010-02-02


    I'm trying to get this command line to  work.

    7z e *.zip -r

    Basically, I want to extract all zip files in all the subfolders and keep their destination intact.

    In addition, how do I set them to auto rename themselve while unzipping too.

    Many thanks.

  • Giorgio Tani

    Giorgio Tani - 2010-02-02

    You should use x to extract the archived objects keeping the folders structure, rather than e that extracts all files to the same output path.
    The policy to apply if the destination contains objects with the same name of objects being extracted can be set with the -ao patameter: -aoa overwrites all existing files, -aos skip extracting if a file with same name exists in destination, -aou rename files being extracted in case of naming conflict, -aot instead renames existing files.

  • Anonymous - 2010-02-03


    Thanks, I haven't tried this yet. (will do it later back home)

    So I assume the command line would be.

    7z x *.zip -r -aou

    The original command line did not work at all. It does not seem to be able to find any zipped files in any of the subfolders. Which I assume, the name of the subfolders do not matter much, except they must be located in the root directory of where the 7z.exe is executed?



    command line done from c:\  and will extract all 1, 2, 3.zip files from those sub directories.

    Thanks again

  • fernando

    fernando - 2010-02-03

    Switch -r (Recurse subdirectories) is not for your task. One method is to use a FOR/IN/DO loop to recurse the directory structure performing the desired 7-Zip command upon each ZIP archive.

    Look at the below command line. If it "echos" correct, remove the "ECHO."…

    FOR /R "C:" %I IN (*.zip) DO ECHO.7z x "%I" -aou
  • Anonymous - 2010-02-03

    Hi ikxcsshcm7,

    I'm sorry but I don't understand how to use that command line.

    How exactly do I execute that from the cmd window @ the root directory?


  • fernando

    fernando - 2010-02-04

    Ensure 7z is in the root directory or on PATH.
    Type (or paste) the above command line at the CMD prompt in the root directory and press Enter.

  • Anonymous - 2010-02-10

    Thanks alot ikxcsshcm7,

    Your command line,

    FOR /R "C:" %I IN (*.zip) DO ECHO.7z x "%I" -aou

    Does not work exactly and it did not unzip any of the zipped files in the subfolders.

    However, using this without ECHO

    FOR /R "C:" %I IN (*.zip) DO 7z x "%I" -aou

    does work, except it seem to extract all the files into the root directory instead of going to their respective sub folders.

    In a general sense, it is of no big issue, but would be useful if it can do it.

    Many thanks again :)

  • fernando

    fernando - 2010-02-11

    Sorry… left a bit off. Try:

    FOR /R "C:" %I IN (*.zip) DO @ECHO.7z x "%I" -aou -o"%~dpI"

    If it "echos" correctly, remove the "@ECHO."

  • fernando

    fernando - 2010-02-11
    $ :: Directory Structure Before Extraction:
    $ TREE X: /A /F
    Folder PATH listing for volume TEST
    Volume serial number is 1234-ABCD
    |       archiv1.zip
    $ FOR /R "X:" %I IN (*.zip) DO 7z x "%I" -aou -o"%~dpI"
    $ 7z x "X:\sub1\archiv1.zip" -aou -o"X:\sub1\"
    7-Zip 4.65  Copyright (c) 1999-2009 Igor Pavlov  2009-02-03
    Processing archive: X:\sub1\archiv1.zip
    Extracting  dir1
    Extracting  dir1\file1.txt
    Everything is Ok
    Folders: 1
    Files: 1
    Size:       1848300
    Compressed: 5611
    $ 7z x "X:\sub2\archiv2.zip" -aou -o"X:\sub2\"
    7-Zip 4.65  Copyright (c) 1999-2009 Igor Pavlov  2009-02-03
    Processing archive: X:\sub2\archiv2.zip
    Extracting  dir2
    Extracting  dir2\file2.txt
    Everything is Ok
    Folders: 1
    Files: 1
    Size:       4620750
    Compressed: 13670
    $ :: Directory Structure After Extraction:
    $ TREE X: /A /F
    Folder PATH listing for volume TEST
    Volume serial number is 1234-ABCD
    |   |   archiv1.zip
    |   |
    |   \---dir1
    |           file1.txt
        |   archiv2.zip
  • CarcaBot

    CarcaBot - 2010-10-10

    Yes, this command is working nice for me , but what  is not good , the subfolders structure is not kept.
    To keep the archive structure you have to run

    FOR /R "C:" %I IN (*.zip) DO @ECHO.7z x "%I" -aou -o"%~dpI\*"

    good luck

  • euliutos

    euliutos - 2011-09-22

    This thread was very helpful guys!
    I have a slightly different problem
    I want to extract the contents of the zip files to another root directory, but to help in sorting, i want to retain the path in the file name.

    For example, I have the following


    And I am trying to extract them like this:


    Finally, all the files will be extracted in the same location, but the file name will depict their original paths.

    Any help guys? I am clueless!

  • Chiliem

    Chiliem - 2012-02-03

    I have one uncompressed folder containing several sub folders with scattered .jar, .tar and .iso files - apart from non-archive file formats.
    What I would like is to extract all extractable files in their directories and afterwards delete the archive file formats.

    Can this be done in one command line?

    thx a lot!

  • fernando

    fernando - 2012-02-03

    TEST something like the below command line

    FOR /R %I IN (*.iso *.jar *.tar) DO (7Z x "%I" -aoa -o"%~dpI\*" |FIND "Everything is Ok" >nul &&DEL "%I" ||ECHO.%I : EXTRACT FAIL - ARC NOT DELETED >>ERR.TXT)

    Above is one single line.

  • Chiliem

    Chiliem - 2012-02-04

    Thx. There's another problem tho. It seems that when I try to open 7za.exe, the standalone console window disappears straight away. Any ideas on this?


  • LogicDaemon

    LogicDaemon - 2012-06-24

    btw, you just can

    7z x archive.7z -o*

    or even

    7z x *.7z -o*

    (this is 7z-specific, won't work with others)


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks