Home » Questions » Computers [ Ask a new question ]

7Zip - Command Line : Exclude folder(s) by wildcard pattern?

7Zip - Command Line : Exclude folder(s) by wildcard pattern?

Any idea how to exclude a wild-carded path(s) from a command-line 7zip command?

Asked by: Guest | Views: 205
Total answers/comments: 2
Guest [Entry]

"To exclude the bin and obj folders recursively you can use the command:

7z.exe a -t7z archive.7z FolderToArchive\ -mx0 -xr!bin -xr!obj"
Guest [Entry]

"Based on @zhazha's answer and make it more clear about how to exclude sub folders exactly. On Windows 10, to backup a Visual Studio solution root folder:

D:\VS2019\Sln1

then:

//goto the parent of the root folder first which make thing clearer
//not sure what will happen if you go into the root folder
cd D:\VS2019
""<path-of-7z>\7z.exe"" a -tzip -mx0 Sln1_backup.zip Sln1 -x!Sln1\.vs -x!Sln1\Debug -x!Sln1\Release -x!Sln1\lib -x!Sln1\Project1\x64 -x!Sln1\Project2\obj

Then you can be sure only the specified sub folders are excluded, for example Sln1\Project3\obj or Sln1\Project4\lib will not be excluded unintentionally. Works for the hidden huge .vs folder.

-mx0 means archive/no compression."