Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

-x!bin* -x!bin*.* -x!\bin* -x!\bin*.* -x!\bin\* -x!\bin\*.*

None seem to exclude. Is this simply a limitation of 7zip?

share|improve this question
add comment

2 Answers

up vote 43 down vote accepted

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
share|improve this answer
    
Gah! I was over-complicating it with the slashes, plus I totally ignored the 'r' portion. Thanks! –  Yoopergeek Jan 18 '10 at 18:37
3  
For everyone else: if you want to ignore only the files in the root directory, use -xr0!*.zip - at least I couldn't get it to work without the r0. –  Oliver Feb 23 '13 at 9:46
add comment

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 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

.\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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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