8

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.

Ricardo
  • 439

2 Answers2

6

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.

surfasb
  • 22,896
0

The reason for this error is here. Marco

When you need to include the file path prefix.

Don't use D:/test/* or ./test/* or -spa.

Try this conmand:

7z a test.7z -ir!"test/*.txt" -ir!"test/*.html"
ZSkycat
  • 131