Zipping everything in directory with 7z except one file or one file type

penguinsource picture penguinsource · Nov 19, 2012 · Viewed 18.5k times · Source

i'd like to zip everything except one file

7z a -tzip files.zip *

this will zip all the files in my current directory.. is there a way I can tell it to not zip one file or one file type ?

Answer

Joshua McKinnon picture Joshua McKinnon · Nov 20, 2012

Per the 7za command-line help, you use the -x switch to do this:

-x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames

To exclude the file foo.txt you would add:

-x!foo.txt

To exclude all .html files (*.html) you would add:

-x!*.html

You can add multiple -x entries to exclude multiple filenames and/or wildcards in one zip command. Adding the following will exclude foo.txt and *.html:

-x!foo.txt -x!*.html

So with your example, this would add all files to files.zip EXCEPT files named "FILENAME" or that matched the *.extension wildcard:

7za a -tzip files.zip * -x!FILENAME -x!*.extension