Windows – How to exclude a folder in 7zip

7-zipcommand linecompressionwindows

I want to compress the folder C:\Temp but without a specific subfolder (e.g. C:\Temp\test). How can I do that with 7zip?

I've come up with the following command:

c:\Temp>7zip a -t7z test.7z c:\temp\ -mx0 -x!c:\temp\test\*

but it dos not work since the output is:

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Scanning

Updating archive test.7z


Compressing  Temp\admin.PNG
Compressing  Temp\test\admin2.PNG   <<<<<< this file should not be added to the archive
Compressing  Temp\first.txt

Best Answer

As tested on my system:

7zip a -t7z -mx0 -x!test\* test.7z c:\temp\ 

If you're in the source directory, the files are stored with relative paths, so the test folder looks like test\file1.txt, not c:\temp\test\file1.txt.

Please note, with the -mx0 switch, you're not compressing the files, only copying them fullsize into the archive.

Related Question