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.

2 Answers 2

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

4
  • 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
    Commented Oct 22, 2015 at 7:00
  • I don't know. Have you tried it?
    – DavidPostill
    Commented Oct 22, 2015 at 7:55
  • Yes I have tried it and it works. But is there a better way to write that code?
    – luisdev
    Commented Oct 23, 2015 at 13:32
  • I don't think so.
    – DavidPostill
    Commented Oct 23, 2015 at 13:33
1

This one works for me and 'aos' parameter will skip existing files.

7za x '-xr!*.mp3.bin' '-aos' file
# nice -n 18 7za x '-xr!*.mp3.bin' '-aos' Environment-voice-20190106-20190108-20230717101500.zip

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C.UTF-8,Utf16=on,HugeFiles=on,64 bits,16 CPUs Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz (50657),ASM,AES-NI)

Scanning the drive for archives:
1 file, 1386663243 bytes (1323 MiB)

Extracting archive: Environment-voice-20190106-20190108-20230717101500.zip
--
Path = Environment-voice-20190106-20190108-20230717101500.zip
Type = zip
Physical Size = 1386663243
64-bit = +

 94% 1289
... Everything is Ok

Files: 2930
Size:       27653690
Compressed: 1386663243

You must log in to answer this question.

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