1

How do I extract all the files in a 7-Zip .7z archive EXCEPT certain file types, using the 7-Zip command line?

Example: backup.7z contains files of type:

  • .xls
  • .xlsx
  • .doc
  • .docx
  • .pdf
  • .txt
  • .png
  • .gif

Using the 7-Zip command line, how do I extract all the files from that backup.7z archive EXCEPT the .doc and .docx files?

The .7z archive contains files and folders and I want all the files and folders - EXCEPT the .doc and .docx files - to be extracted.

I am using MS Windows 7.

0

How do I extract all the files in a 7-Zip .7z archive EXCEPT certain file types

Use the -x (Exlude filenames) switch.

7z e backup.7z -x!.doc


-x (Exclude filenames) switch

Specifies which filenames or wildcarded names must be excluded from the operation.

Multiple exclude switches are supported.

Syntax

-x[<recurse_type>]<file_ref>

<recurse_type> ::= r[- | 0]
<file_ref> ::= @{listfile} | !{wildcard}

See -i (Include) switch description for information about option parameters.

Examples

7z a -tzip archive.zip *.txt -x!temp.*

adds to the archive archive.zip all .txt files, except temp. files.

Commands that can be used with this switch

a (Add), d (Delete), e (Extract), l (List), t (Test), u (Update), x (Extract with full paths)

Source -x (Exclude filenames) switch

  • Is this the best way to exclude multiple file types: 7z x backup.7z -oC:\temp -x!*.mp3 -x!*.mp4 -x!*.swf -x!*.ppt -x!*.psd – luisdev Oct 22 '15 at 7:00
  • I don't know. Have you tried it? – DavidPostill Oct 22 '15 at 7:55
  • Yes I have tried it and it works. But is there a better way to write that code? – luisdev Oct 23 '15 at 13:32
  • I don't think so. – DavidPostill Oct 23 '15 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.