4

I'm trying to exclude a certain directory when building an archive using zip. Here's what I have tried:

$ zip home.zip -y -r HOME -x '/AppData' -x '/AppData*' -x '/AppData/*' -x 'AppData' -x 'AppData*' -x 'AppData/*'

Produces:

  adding: HOME/ (stored 0%)
  adding: HOME/AppData/ (stored 0%)
  adding: HOME/AppData/a (deflated 39%)
  adding: HOME/AppData/LocalLow/ (stored 0%)
  adding: HOME/AppData/LocalLow/Sun/ (stored 0%)
  adding: HOME/AppData/LocalLow/Sun/Java/ (stored 0%)
  adding: HOME/AppData/LocalLow/Sun/Java/a (deflated 39%)
  adding: HOME/AppData/LocalLow/Sun/Java/Deployment/ (stored 0%)
  adding: HOME/AppData/LocalLow/Sun/Java/Deployment/a (deflated 39%)

My directory tree looks like:

./HOME
./HOME/AppData
./HOME/AppData/a
./HOME/AppData/LocalLow
./HOME/AppData/LocalLow/Sun
./HOME/AppData/LocalLow/Sun/Java
./HOME/AppData/LocalLow/Sun/Java/a
./HOME/AppData/LocalLow/Sun/Java/Deployment
./HOME/AppData/LocalLow/Sun/Java/Deployment/a

So it seems to be ignoring my -x options.

What is the correct syntax for the -x option?

Found this post but as you can see above, it didn't solve my problem.

I am using Info-ZIP 3.0 on Cygwin 1.7.35 on Windows 7.

3 Answers 3

8

Try putting it as -x '*AppData/*'

5
  • Yes, that does work, but it also matches any paths that has "AppData" in it, not just specifically the path that starts with "AppData".
    – GreenGiant
    Jul 29, 2015 at 17:57
  • In that case using absolute paths will work
    – neuron
    Jul 29, 2015 at 17:58
  • Could you provide an example of what you mean by an absolute path?
    – GreenGiant
    Jul 29, 2015 at 18:11
  • @GreenGiant Absolute pathname is a pathname that begins with a slash. Absolute is for example /home/user, relative when PWD is /home is user.
    – MichalH
    Jul 29, 2015 at 19:18
  • Ok. I guess what I want is a relative path, so that my command doesn't have to change based on what the current directory is.
    – GreenGiant
    Jul 31, 2015 at 2:30
2

Just do

-x */AppData/*
# or
--exclude */AppData/*

Don't forget to add the first slash, because otherwise it also matches any paths that has "AppData" in it, not just specifically the path that starts with "AppData".

-1

Looks like the path that zip is matching against includes the root path element you give it, unless the root is .

In my case, if I wanted to exclude anything under LocalLow, I needed:

$ zip home.zip -y -r HOME -x 'HOME/AppData/LocalLow/*'

Yielding:

  adding: HOME/ (stored 0%)
  adding: HOME/AppData/ (stored 0%)
  adding: HOME/AppData/a (deflated 39%)

If you instead cd into the HOME directory and use . as the root, you don't need to specify the root element in the exclude path:

$ cd HOME
$ zip home.zip -y -r . -x 'AppData/LocalLow/*'

  adding: AppData/ (stored 0%)
  adding: AppData/a (deflated 39%)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .