Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that the 7-zip command to add a folder to an archive is, e.g.:

"c:\program files\7-zip\7z" a c:\myFolder

And the command to add only files of a certain extension to an archive is, e.g.:

"c:\program files\7-zip\7z" a c:\myFolder\*.jpg -i!c:\myFolder\*.pdf

How do I add a folder to an archive containing only files of a certain extension? I tried:

"c:\program files\7-zip\7z" a c:\myFolder\ -i!c:\myFolder\*.jpg -i!c:\myFolder\*.pdf

but that just added all the files in the folder, not just the .jpg and .pdf. What's more, it also added subfolders, which I didn't want.

Is there a way to use the -x switch so that I can say, "add all files except those that are not these extensions, and don't add any subfolders"?

share|improve this question
up vote 1 down vote accepted

Your command told 7z to add the data in myFolder, then also to add stuff in myFolder that was a jpg, then that which is a pdf. You can just use:

"c:\program files\7-zip\7z" a -i!c:\myFolder\*.jpg -i!c:\myFolder\*.pdf

and that will pick up the correct files through the inclusion filters.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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