0

When I do

7z a test.zip -x!*discarded* test

with

test/
test/a.txt
test/subfolder/
test/subfolder/a.txt
test/subfolder/discarded/
test/subfolder/discarded/a.txt
test/subfolder2/a.txt
test/subfolder2/subfolder3/a.txt
test/subfolder2/subfolder3/discarded/
test/subfolder2/subfolder3/discarded/a.txt

then, unfortunately, everything is still included!

How to exclude every file/folder like */discarded/*? (or, alternatively, exclude any file/folder whose absolute path contains discarded?)

Also, how to exclude all files ending by .txt? (-x!*.txt doesn't work)

I use 7z on Windows.

Note: 7Zip - Command Line : Exclude folder(s) by wildcard pattern? didn't help here.

Basj
  • 1,809
  • 12
  • 58
  • 100
  • @KamilMaciorowski In my case, the shell is Windows. I was looking for a crossplatform way, since I use 7z both from Win and Linux, but for simplicity, my need here is first for Windows. – Basj Feb 29 '24 at 22:55
  • 1
    According to your linked ticket, it should be 7z a test.zip test -xr!discarded. That did not work? – LPChip Mar 01 '24 at 09:57
  • @LPChip I did a new test, and I confirm it works now. I don't know what happened. – Basj Mar 01 '24 at 10:40
  • 1
    I thought that looked correct. Glad it worked now. Maybe you did not write the r for recursive? -x!... would not work, but -xr!... would match the word and exclude it recursively. – LPChip Mar 01 '24 at 10:45
  • 1
    Might be nice to credit @LPChip in your answer – Sandeep Bansal Mar 01 '24 at 11:37
  • @SandeepBansal Yes of course, I always do it in such cases, I forgot here! Fixed now! Thanks! – Basj Mar 01 '24 at 20:05

1 Answers1

1

After a new test, as suggested by LPChip, this works:

7z a test.zip -xr!discarded -xr!*.txt test
Basj
  • 1,809
  • 12
  • 58
  • 100