Windows – 7-Zip command line option to include only one kind of file recursively

7-zipwindowswindows 7

I want to add any txt file under a given path using 7-Zip.

Looking at the help I tried this:

7za a  -ir!*.txt bla.7z c:\initial\path

This ended up including every single file, txt or not.

Looking at this question I tried to do this:

7za a  -ir!.\*.txt bla.7z c:\initial\path

This ended up giving me this awkward message:

Error:
Duplicate filename:
c:\initial\path\CLI\0003\readme.txt
c:\initial\path\CLI\0003\readme.txt

Interestingly the -xr option works fine for me. For example if I try:

7za a  -xr!*.txt bla.7z c:\initial\path

every file but the txts are included.

Best Answer

  • Try 7z a bla.7z -r c:\initial\path\*.txt

    You don't need to use the -i switch unless you want to include more than one set of wildcards. In that case, you'd want to you'll want to use multiple -i for each set of wildcards on the same command line. But that is a big big pain in the rear and not recommendation.

    It is better to output the file paths into a listfile and feed the list of paths into 7z.