How do I exclude hidden directories when creating an archive using 7zip's command line version?
I tried -x!".*"
, but that didn't work.
You need to add the r
("recurse") flag to the -x
option if you want it to match files inside subdirectories.
For example, the following creates an archive from the whole directory tree under folder/
except for any files that start with a dot:
7z a -xr'!.*' archive.7z folder/
I had the same problem on windows 7 64bit 7zip.
After doing some research I found the following points:
1) single/double quotes ' " does not work on windows - 7zip says incorrect wirdcard
2) excluding based on file/folder attributes is not possible - only option is either to exclude with wild cards or make an exclude list.
3) in -x option, file is denoted as < path>\< filename.ext> and a folder as < path>\< folder>/ (with a slash at the end)
4) format 1: with ! mark (pattern directly with command) you can give something like:
a) 7z a -xr!<path>\<folder to exclude>/ archive.7z <zip folder>/
This excludes .svn folder in any path from zip folder recursively
b) 7z a -xr!*\.svn/ archive.7z <folder>/
5) format 2: with @ symbol you can give exclude list like this:
a) 7z a -xr@<7z exclude list file> <archive name>.7z <folder>/
where an exclude list file can have:
*\.svn/
*\output/
*\Document/
*\Measurements/
*.xlsx
*.bak
my favorite option is to use an exclude list
I had a problem on Win64 and an exclude file. I couldn't get the .git
folder excluded. The simple ".git\" didn't work, neither any other usual patterns. In the end excluding "*git\" worked (note: no dot).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With