25

I'm using the 7-Zip commandline to extract a ZIP archive called abc.zip which is an archive with a folder called 'zipper' with three text files in it (a.txt, b.txt, and c.txt).

My problem is when I extract it with the following command:

7z e C:\abc\abc.zip -y oC:\abc

7-Zip extracts everything, but it doesn't extract the folder 'zipper', it just extracts a.txt, b.txt and c.txt and puts them in the output destination (that is, C:\abc).

How can I make 7-Zip just extract the actual folder?

4 Answers 4

34

You need to use 7z x archive.zip to extract with full paths. See: http://sevenzip.sourceforge.jp/chm/cmdline/commands/extract_full.htm

1
  • +1 thought the switch -e would be sufficient. Commented Feb 19, 2020 at 2:51
12

There should probably be a hyphen in front of the o:

-oC:\abc

Also consider the -r option for recursion.

1

I had to solve a similar problem. Here is the code I used. This script receives a folder and unzips all zips (and deletes them afterwards). The trick is to unzip the data into a special folder. A little bit edgy but it works...

@echo off

set SEVEN_ZIP_HOME=C:\Program Files\7-Zip

set TEMPDIR=temp

set WORKING_DIR="%1"

if "%WORKING_DIR%"==""  set WORKING_DIR=%~dp0

cd /d %WORKING_DIR%

if not exist %TEMPDIR% md %TEMPDIR%

for %%i in ("%WORKING_DIR%\*.zip") do call :unzipAndDelete "%%i"

rd %TEMPDIR%

goto :end

:unzipAndDelete 

set ZIP_FILE=%~1

call :extractName %ZIP_FILE%

call "%SEVEN_ZIP_HOME%\7z.exe" e "%ZIP_FILE%" -o./%TEMPDIR%

copy .\%TEMPDIR%\*.* %FILENAME%.log

del .\%TEMPDIR%\*.* /q

del "%ZIP_FILE%"

goto :end

:extractName 

set FILENAME=%~n1
goto :end


:end
0
0

Be careful with considering -r The doc explicitly says :-)

-r[-|0]
Recurse subdirectories (CAUTION: this flag does not do what you think, avoid using it)

1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 20, 2022 at 9:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .