7zip: Exclude hidden directories [closed]
Asked Answered
A

4

14

How do I exclude hidden directories when creating an archive using 7zip's command line version?

I tried -x!".*", but that didn't work.

Ambition answered 20/4, 2015 at 13:32 Comment(1)
If you know the pattern of hidden file then its very easy like .svn or .git etc.. but if there is no pattern in that case you must go for staging.Masse
S
20

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/
Subdominant answered 9/1, 2016 at 15:26 Comment(1)
n.b.: Note that the exclamation mark has to be quoted for bash and zsh.Subdominant
B
14

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

Bevash answered 10/3, 2017 at 13:21 Comment(3)
Single quotes worked for me inside a PowerShell script.Gubernatorial
Thanks for the detailed explanation and examples! When doing a 7z a -xr!*\node_modules/ archive.7z d:\Workspace\my-project using the trailing slash for node_modules folder or not (your point 3) ) did not make a difference though.Holdfast
Thanks for the info and appreciation. The newer versions may have modified -x option and interpretation. I will check again and modify my answer.Bevash
R
4

this would work for ignoring hidden files ... 7z.exe a -xr!.git\ -xr!*~ ".zip"

Radiochemistry answered 14/12, 2018 at 15:54 Comment(1)
this is what i need, to exlude .git hidden folders , and it works!Sym
D
2

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

Damali answered 1/7, 2020 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.