Any idea how to exclude a wild-carded path(s) from a command-line 7zip command?
I'm doing something this:
7z.exe a -t7z archive.7z FolderToArchive\ -mx0
and would like to exclude any \bin*.* or \obj*.* folders found underneath "FolderToArchive". To exclude files you can use the -x parameter. The help file gives this example for using -x:
7z a -tzip archive.zip *.txt -x!temp.*
That's great for excluding a file. But, again, I would like to exclude a wildcard-specified folder. Under my "FolderToArchive" there are multiple folders, under those folders there may or may not be "bin\" and "obj\" folders. I would like to not include these in the archive.
I've tried patterns like:
None seem to exclude. Is this simply a limitation of 7zip?
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
To avoid bug, use -r or -xr carefully.
suppose you have directories like:
and run the command:
7z a -t7z archive.7z .\path1\path2 .\path3\path4\path5 -xr!bin
what you got in archive.7z:
That is, the path2 and path5 became the TOP folder in zip file. and both bin directories were excluded.
-x only support path/filename RELATIVE TO THE FINAL PATH IN ZIP FILE.
So, if you only want to exclude
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.
I have folders and files on my disk
Can I create an archive with 7z command line version with folder structure similar to this?
You would need to create a batch/script file containing something like this:
7z a: -r -t7z MyArchive.7z C:\builds\main.exe D:\components\a\testa.exe D:\components\b\testb.exe D:\components\c\testc.exe D:\dependencies\abc.dll
Commands are as follows - a: to add to archive, -r to make recursive, -t7z .7z archive file type.
Note: this is untested.