11

The man page for 7z simply says

Do not use "-r" because this flag does not do what you think.

The only documentation I can find basically restates the same thing.

   -r[-|0]
          Recurse subdirectories (CAUTION: this flag does not do what  you
          think, avoid using it)

So, what does it do, and why does the author of this documentation think I think it does something else?

This is 7zip 9.04 on Debian Squeeze (i.e. pretty old).

tripleee
  • 3,191
  • 1
    Weird. I use the -r switch all the time. Does what it should. I'm using 7-Zip 9.20 on Windows. The documentation that comes with 9.20 doesn't mention anything about avoiding this switch. – misha256 Jul 03 '15 at 10:37
  • 1
    They have a forum where you can post questions. I think you're more likely to get an answer by emailing the author... http://sourceforge.net/p/sevenzip/discussion/ – Dave Jul 03 '15 at 11:26
  • @misha256. It really does not do what you think it does. Please see my answer below as it's quite an odd behaviour that you won't even notice except for a few edge cases. – YorSubs Oct 18 '22 at 11:11

2 Answers2

4

From the 7-Zip user manual (chm)

Specifies the method of treating wildcards and filenames on the command line.

enter image description here

Moab
  • 58,308
  • 7-zip.org doesn't have links to the CHM files, but I found a copy of this at http://sevenzip.osdn.jp/chm/cmdline/switches/recurse.htm – tripleee Jul 06 '15 at 07:26
  • It is included with the program after you install it. – Moab Jul 06 '15 at 12:42
  • Yes, I get it in /usr/share/doc/p7zip-full/DOCS/MANUAL on Debian, but I can't link to that. A screenshot is not searchable or copy/pasteable so I wanted to include a link before accepting this answer: feel free to include it in the answer itself, obviously. – tripleee Jul 06 '15 at 13:05
  • 1
    We use images here due to link rot. – Moab Jul 06 '15 at 16:07
1

I never fully understood what 7z.exe was doing with the -r flag until today, and believe this is the correct answer and the meaning behind the authors cryptic note.

In my script using 7z.exe I was using -r a lot until I discovered that an archive had a bunch of subfolders (but I had specified none!). Then I realised that for one of the files that I specified on the command line, 7z.exe decided to look in all subfolders adjacent to the location that my files are. Although I had specified no folders in my target files, 7z.exe decided to look in all subfolders and found some files with the same name deeply nested in one of those folders. You can see that it is doing this by the text "Scanning the drive" and it traverses all subfolders before performing the zip. The solution is to only ever use -r0 - as long as you specify any mix of folders / filenames and no wildcards, it will still recursively add any folder objects that you specify, but will no longer try to scan the entire filesystem around/beside the current location. I believe that this is what the author meant by "this flag does not do what you think, avoid using it".

YorSubs
  • 881