35
4
If I have an archive, for example, some.zip
that contains one or more files, how can I extract only one file (I know the name of the file) with 7-Zip from the command line in Windows?
35
4
If I have an archive, for example, some.zip
that contains one or more files, how can I extract only one file (I know the name of the file) with 7-Zip from the command line in Windows?
33
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
14
You just add the filename at the end.
7z e [archive.zip]
-o[outputdir] [fileFilter]
1How can I add multiple file filters, say .XML
and .zip
? Sorry if I'm hijacking this thread, I just didn't want to add a duplicate question. – Fr0zenFyr – 2014-06-21T05:25:11.260
It's a different question @Fr0zenFyr. To make it clear that it is not duplicate, you can reference this question in your own, and then specify how yours is different. – music2myear – 2017-01-23T23:18:13.177
@music2myear: Thanks for clarification. Top voted answer by zionyx already includes a solution. My comment is over 2 years old, so it would be a reasonable guess to assume that I either used above solution or already posted a question and found an answer (BTW, this was my case). My resolved post is on SO and original thread created before my comment is here so I couldn't link to this question. :)
– Fr0zenFyr – 2017-01-25T10:00:45.200Note : as it is written here, do not put space between -o and outputdir. – King's jester – 2019-10-25T09:38:29.873
4
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.
2Is that the relative path within the archive? – music2myear – 2017-01-23T23:18:35.357
Yes, the "folderwithin" is a folder at the root of the archive. – King's jester – 2019-10-25T08:37:56.853
1
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
1How can I add multiple file filters, say
.XML
and.zip
? Sorry if I'm hijacking this thread, I just didn't want to add a duplicate question. – Fr0zenFyr – 2014-06-21T05:25:44.5201Should be fine by separating the filters by space. See the edited answer above. :) – zionyx – 2014-08-26T14:06:16.023
And how do I extract a specific file from an archive inside the archive? Lets say the file I'm looking for is "MyFile.txt" inside "SubArchive.zip" inside "MainArchive.zip". Is this possible? – PeterCo – 2017-10-27T12:14:37.367
1@PeterCo, I think the command is only capable to extract
SubArchive.zip
from theMainArchive.zip
in your case. You may run a follow up command to extractMyFile.txt
fromSubArchive.zip
after the initial extraction. – zionyx – 2018-01-05T09:09:00.973