The Computer Oracle

Extract a certain file from an archive with 7-Zip from the command line

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles

--

Chapters
00:00 Extract A Certain File From An Archive With 7-Zip From The Command Line
00:19 Accepted Answer Score 26
00:28 Answer 2 Score 58
01:02 Answer 3 Score 9
01:31 Answer 4 Score 4
01:50 Thank you

--

Full question
https://superuser.com/questions/321829/e...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #commandline #archiving #extract #7zip

#avk47



ANSWER 1

Score 58


As a follow-up to surfasb's answer, add a -r flag at the end to recurse:

7z e [archive.zip] -o[outputdir] [fileFilter] -r

Multiple filters support:

7z e [archive.zip] -o[outputdir] [fileFilter_1] [fileFilter_2] -r

Example:

Multiple filters command line:

7z e archive.zip -o outputdir *.xml *.dll -r

PS: I use 7za.exe instead of 7z.exe. This is the actual command I use in my script:

7za.exe x archive.zip -o outputdir *.xml *.pdb *.exe *.ocx *.dll -r



ACCEPTED ANSWER

Score 26


You just add the filename at the end.

7z e [archive.zip] -o [outputdir] [fileFilter]



ANSWER 3

Score 9


If you look at the man page for 7z you will find that the following command can be used to extract a file from a 7z archive (though the usage of path is missing from the man page):

7z x <archive> <path to file>

Examples:

7z x backup.7z *.html
7z x backup.7z folderwithin/myfile.html

Alternatively you could use e.

The command line version users guide seems to have more information on the actual usage.




ANSWER 4

Score 4


Note that 7z has the following syntax (observe the spaces and quotes surrounding the "-oMy Folder" option to set the output folder name, took me hours to figure out, as I originally did this – the wrong way: * -o "My Folder" *):

7z e "my zip.zip" "-oMy Folder" *.jpg "all of these.*" -r