7-Zip is an awesome tool, but sometimes it works in a strange way. Consider the following directory D:\dir layout:

foo   <DIR>
bar   <DIR>
baz   <DIR>
empty <DIR> -- this directory is empty by intention

Now when executing the following commands:

>cd D:\dir
>7z a -r -bb3 -mx9 -mmt -ms empty.7z empty
7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

Scanning the drive:
    0M Scan foo\bar\baz

For some reason 7-Zip scans directories that are not relevant to the compression process. This is relevant to 7-Zip [64] 16.04, but it worked like that in much older versions. Not sure if it's also reproducible on Linux.

How do I disable the scan and make 7-Zip analyze the specified directory recursively only?


Igor Pavlov, the creator of 7-Zip, has kindly clarified to me how 7z works for such a scenario.

  • Could not reproduce on Windows.
    – user477799
    Apr 2 '17 at 15:37
  • Are your "non-relevant" directories big enough so that 7z could take some time to scan them? What if you try to archive an empty directory, say C:\7ztest, from the root of your drive C? Apr 2 '17 at 15:58
  • Aha! Now I am seeing it. Maybe you should file a bug report.
    – user477799
    Apr 2 '17 at 16:00
  • @FleetCommand Interesting. I bet that 7z worked like that even for much older versions (if I'm not mistaken I used a 2010 version before 16.0.4), and it's hard to believe that Igor Pavlov is not aware of this behavior. I'll consider a bug report, thank you. Apr 2 '17 at 16:09

I was asking the same question at the official 7-Zip forums, and got the reply from Igor Pavlov. I would like to get the answer from Igor at the site, but he seems not to have an account here. He suggests just to remove the -r switch, since 7z uses recursive search by default:

Your command searches empty file or folder in all subfolders.
Remove -r switch.


Here is the respective excerpt from the official FAQ:

Why doesn't -r switch work as expected?

In most cases you don't need -r switch. 7-Zip can compress subfolders even without -r switch.

Example 1:
7z.exe a c:\a.7z "C:\Program Files"
compresses "C:\Program Files" completely, including all subfolders.

Example 2:
7z.exe a -r c:\a.7z "C:\Program Files"
searches and compresses "Program Files" in all subfolders of C:\ (for example, in "C:\WINDOWS").

If you need to compress only files with some extension, you can use -r switch:
7z a -r c:\a.zip c:\dir\*.txt
compresses all *.txt files from folder c:\dir\ and all it's subfolders.

  • 2
    This is still pretty confusing. I hope someday Igor decides to remove/rename/fix the -r switch.
    – Jake
    Mar 5 '20 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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