I know you can create a text file containing a list of files and then tell 7zip to reference this file so that it can exclude them from the archive, but I cannot find the syntax for that. Can someone help?

3 Answers 3


After a few hours of searching, I finally figured it out. Here's the switch syntax:

7z a -xr@exclude.txt backup.7z c:\whatever\*

Notice -xr instead of -x. The r indicates recursive so it can match excluded files in deep folder hierarchies. Also, the format of the text file can be at least ANSI or UTF-8.

As for the file containing the files, as OldWolf said, it's a list separated by carriage returns like this:


Works like a charm.

  • 1
    Thanks! I was trying to do exclude with the wildcard option and it turns out I was missing the r option. This is the correct way to exclude PNG files recursively in bash (single quotes to stop bash from expanding ! and *): -xr'!*.png' (edit: single quotes instead of escape)
    – thomasa88
    Jul 27, 2015 at 8:48

I think you want the -x switch with @

7z a -t7z my.zip * -x@myexclusion.lst

In retrospect, I realized you may have meant you wanted the syntax for the listfile. It should be a newline separated list. You may be running into an encoding issue. 7z expects it to be in UTF-8 format, you can override that with the -scs switch or you can tell notepad to save the file in UTF-8 format

  • 2
    Thanks for the reminder about file encoding. I have been puzzling for hours as to why my exclusion list was not being obeyed. I produce the file in a PowerShell script using Out-File which defaults to Unicode. Changing it to output UTF8 and suddenly everything just works.
    – WileCau
    Apr 27, 2014 at 12:23

If your list is going to be really short, you can have more than one -x flag:

7z a -r CppSourceJBR.zip *.cpp .h -x!stdafx. -x!targetver.h

BTW while testing I had to keep deleting the .zip file. When I forgot that, for instance targetver.h was still in the ZIP from the last run.

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.