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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2010-02-03
Hi,
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?
e.g.
c:\sub1\1.zip
c:\sub2\2.zip
c:\sub3\3.zip
command line done from c:\ and will extract all 1, 2, 3.zip files from those sub directories.
Thanks again
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
THis is very useful so far, however I am trying to use the command in powershell and trying to resolve why the syntax seems to not work the same as cmd.
(I am using powershell because dealing with UNC paths not supported with cmd)
PS Microsoft.PowerShell.Core\FileSystem::\\server\folder1\childFolder1\grandCHildFOlder1>FOR /R '\\server\folder1\childFolder1\grandCHildFOlder1' %I IN (*.rar) DO @ECHO.7z x "%I" -aou -o"%~dpI\*"
At line:1 char:4
+ FOR /R '\\server\folder1\childFolder1\grandCHildFOlder1 ...
+ ~
Missing opening '(' after keyword 'for'.
At line:1 char:150
+ ...server\folder1\childFolder1\grandCHildFOlder1' %I IN (*.rar) DO @ECHO.7z x "%I ...
+ ~
Missing property name after reference operator.
At line:1 char:144
+ ... server\folder1\childFolder1\grandCHildFOlder1' %I IN (*.rar) DO @ECHO.7z x "% ...
+ ~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@ECHO' can be used only as an
argument to a command. To reference variables in an expression use '$ECHO'.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
I tried extra parentheses like this:
FOR /R ('\server\folder1\childFolder1\grandCHildFOlder1' %I IN (*.rar)) DO @ECHO.7z x "%I" -aou -o"%~dpI*"
but same error
any ideas?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
when I do
1)FOR /R %I IN (*.gz) DO 7z x "%I" -aou -o"%~dpI\*")
- The files are extracted, but it adds them into a folder with the file name
- eg. c:\source\dir1\dir2\dir-file1\file1
2) FOR /R %I IN (*.gz) DO (7Z x "%I" -aou)
- The files are extracted but all into c:\source with no folder hierarcy retained
How Do i get it to extract in the same directory folder as the file?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
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.
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.
Hi,
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?
e.g.
c:\sub1\1.zip
c:\sub2\2.zip
c:\sub3\3.zip
command line done from c:\ and will extract all 1, 2, 3.zip files from those sub directories.
Thanks again
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."…
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?
Thanks
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.
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 :)
Sorry… left a bit off. Try:
If it "echos" correctly, remove the "@ECHO."
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
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
C:\source\dir1\ar1.zip\abc\file1
C:\source\dir1\ar1.zip\abc\file2
C:\source\dir1\ar1.zip\abc\file3
C:\source\dir1\ar2.zip\abc\file1
C:\source\dir1\ar2.zip\abc\file2
C:\source\dir1\ar2.zip\abc\file3
C:\source\dir2\ar1.zip\abc\file1
C:\source\dir2\ar1.zip\abc\file2
C:\source\dir2\ar1.zip\abc\file3
C:\source\dir2\ar2.zip\abc\file1
C:\source\dir2\ar2.zip\abc\file2
C:\source\dir2\ar2.zip\abc\file3
And I am trying to extract them like this:
C:/destination/dir1_ar1_abc_file1
C:/destination/dir1_ar1_abc_file2
C:/destination/dir1_ar1_abc_file3
C:/destination/dir1_ar2_abc_file1
C:/destination/dir1_ar2_abc_file2
C:/destination/dir1_ar2_abc_file3
C:/destination/dir2_ar1_abc_file1
C:/destination/dir2_ar1_abc_file2
C:/destination/dir2_ar1_abc_file3
C:/destination/dir2_ar2_abc_file1
C:/destination/dir2_ar2_abc_file2
C:/destination/dir2_ar2_abc_file3
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!
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!
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.
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?
thx!
btw, you just can
or even
(this is 7z-specific, won't work with others)
THis is very useful so far, however I am trying to use the command in powershell and trying to resolve why the syntax seems to not work the same as cmd.
(I am using powershell because dealing with UNC paths not supported with cmd)
I tried extra parentheses like this:
FOR /R ('\server\folder1\childFolder1\grandCHildFOlder1' %I IN (*.rar)) DO @ECHO.7z x "%I" -aou -o"%~dpI*"
but same error
any ideas?
I mostly figured it out using the following code:
Although this doesnt delete archive afterwards, but could be modified to do so I believe
Hmm.. I'm also doing recursive folder walks but i can't figure out how to get it to leave the path alone.
For example, I have the following
C:\source\dir1\dir2\file1.gz
C:\source\dir1\dir2\file2.gz
C:\source\dir1\dir3\dir4\file3.gz
C:\source\dir1\dir5\file4.gz
when I do
1)
FOR /R %I IN (*.gz) DO 7z x "%I" -aou -o"%~dpI\*")
- The files are extracted, but it adds them into a folder with the file name
- eg. c:\source\dir1\dir2\dir-file1\file1
2)
FOR /R %I IN (*.gz) DO (7Z x "%I" -aou)
- The files are extracted but all into c:\source with no folder hierarcy retained
How Do i get it to extract in the same directory folder as the file?
I finally found an answer here: https://superuser.com/questions/1224218/batch-extract-files-from-every-archive-with-7-zip
for my purposes:
FOR /F "TOKENS=*" %F IN ('DIR /S /B "*.gz"') DO 7z x "%~fF" -aoa -o"%~pF\"