7Zip - Command Line : Exclude folder(s) by wildcard pattern?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Popsicle Puzzles
--
Chapters
00:00 7zip - Command Line : Exclude Folder(S) By Wildcard Pattern?
01:05 Accepted Answer Score 210
01:17 Answer 2 Score 31
02:23 Answer 3 Score 2
03:03 Thank you
--
Full question
https://superuser.com/questions/97342/7z...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#commandline #7zip
#avk47
ACCEPTED ANSWER
Score 210
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
ANSWER 2
Score 31
To avoid bug, use -r or -xr carefully.
suppose you have directories like:
.\path1\path2\bin
.\path1\path2\src
.\path3\path4\path5\bin
.\path3\path4\path5\src
and run the command:
7z a -t7z archive.7z .\path1\path2 .\path3\path4\path5 -xr!bin
what you got in archive.7z:
.\path2\src
.\path5\src
That is, the .\path2\
and .\path5\
became the top folder in archive.7z, and both bin
directories were excluded.
-x only support path/filename relative to the top folder in archive.
So, if you only want to exclude .\path1\path2\bin
, but to include all the other 'bin' directories, the command should be like this:
7z a -t7z archive.7z .\path1\path2 .\path3\path4\path5 -x!path2\bin
I tried to use absolute path in -x, but never succeed.
Update:
There is an option -spf
in 7z for Linux which works with absolute path.
According to Marco, -spf
is also available on Windows from 7-zip 15.14
ANSWER 3
Score 2
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.