# How to disable 7-Zip directory scan for directories which are not meant to be compressed and added to the archive

7-zipcommand line

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:

>D:
>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?

### Edit

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

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.

http://7-zip.org/faq.html

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.