2

Here's my directory structure (in Windows 8.1):

parentdir\
    child1\
    child2\
        grandchild1\
        grandchild2\
        grandchild3\
        ...
    child3\
    child4\
    ...

Using 7-Zip on commandline, I am trying to automate a compression script to archive all the content of parentdir into parentdir.zip.

In the resulting archive, I need to exclude all the content of child2 except grandchild1.

I could have gone for:

7z a -r parentdir.zip parentdir\* -xr!child2\grandchild2 -xr!child2\grandchild3, etc. 

Problem is there may be any number of grandchildren!

Again, I toyed with something like:

7z a -r parentdir.zip parentdir\* -xr!child2\* -ir!child2\grandchild1\*

The command ran nicely, completely ignoring my second (include) switch.

So, can I actually use both include and exclude switches on the same line? If yes, how? And if not, how can I achieve the goal I just described above, on my directory tree?

Thank you.

1
  • In this case these -x and -i switches contradict each other, so you could do 7z a -r parentdir.zip -ir!parentdir\child2\grandchild1\ from parent of your parentdir. If your directory structure vary every now and then so you would have to change your script often, then you could do it using results of the for command. Start with for /F "tokens=*" %G in ('dir /ad /s /B parentdir') do @echo %G for first look.
    – JosefZ
    Nov 18 '14 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.