Excluding folders in Winrar
Asked Answered
P

4

16

A Day with Winrar

All I wanted to do was exclude folders and their contents using wildcards, and even after reading the docs, it turned into a guessing game...

So my test bed looks like:

C:\!tmp1\f1
C:\!tmp1\f1\f1.txt
C:\!tmp1\f1\a
C:\!tmp1\f1\a\a.txt
C:\!tmp1\f2
C:\!tmp1\f2\f2.txt
C:\!tmp1\f2\a
C:\!tmp1\f2\a\a.txt

And I am executing:

C:\>"c:\program files\winrar\winrar.exe" a -r !tmp1.rar !tmp1

which gives me a rar with !tmp1 as the root (sole top level folder).

The exclude switch is -x<filepathpattern> and may be included multiple times.

So, given that we want to exclude f2, and all its subcontents...

-x*\f2\*

removes the contents, but leaves f2

-xf2

does nothing - includes all

-x\f2

does nothing - includes all

-x*\f2

does nothing - includes all (now I'm mad), so surely it must be..

-x\f2\

nope, does nothing - includes all. So it has GOT to be...

-x*\f2\

hell no, does nothing - includes all. and I already know that

-x*\f2\*

removes the contents, but leaves f2. Onward we go...

-x*f2\

does nothing - includes all. Grrrr. Aha! how about...

-x!tmp1\f2\

nope, does nothing - includes all. WTF. Alright, So it has GOT to be...

-x!tmp1\f2

Holy moly, it worked! Hmmm, then how come....

-x*\f2

does not work? This was the little demon that sent me down this crazed path to begin with and should have worked!

Given all that, do I dare try to go after */a/* directories, removing contents and the dirs?

-x*\a

does not work, of course, does nothing.

-x*\*\a

does not work, of course, does nothing.

-x!tmp1\*\a

nope. But...

-x*\a\*

removes contents of both dirs, but leaves the folders. So, in desperation I can use the -ed switch which will not store empty folders, but this is a broad hack, I want to eliminate the folders specified not all empty folders.

With my animosity growing toward winrar, I am passing the baton of information forward with an eye to that glorious day when we will know how to specifically exclude a folder and its contents using wildcards and not using the -ed switch.

Philemol answered 21/8, 2012 at 20:58 Comment(3)
Consider the possibility that if you exclude a directory and include files in it, it gets created anyway. The documentation says you can include the -x directive multiple times. Did you try -x!tmp1\*\a\* -x!tmp1\*\a?Fishery
No, I didn't try that based on the try of -x!tmp1\f2 worked at pruning that whole limb, so why shouldn't -x!tmp1\*\a work the same? I will try it though, thanks for your input.Philemol
@MarkRobbins, could you ever solve this issue? Could you try my solution?Eventuate
L
16

(Quite old question but still may be relevant)

Maybe what you simply needed was this :

-x*\f2 -x*\f2\*

two exclude switches, should remove directory f2 and all its contents.

Lewls answered 19/9, 2013 at 12:7 Comment(1)
this works. but unfortunately not for folders that have a dot in them like .git so we can't exclude .git folderLoosen
E
9

An even older question by now, but came across this question so I reproduced your folder structure and, at least nowadays (Winrar 5.11, not the latest but quite new), this works:

-x*\f2

So the whole command line is:

"C:\Program Files\WinRAR\Rar.exe" a -m5 -s !tmp1.rar !tmp1 -x*\f2

And this is what is stored in the .rar file:

!tmp1\f1\a\a.txt
!tmp1\f1\f1.txt
!tmp1\f1\a
!tmp1\f1
!tmp1

Similarly, if you use -x*\a, all a folders are excluded, storing this:

!tmp1\f1\f1.txt
!tmp1\f2\f2.txt
!tmp1\f1
!tmp1\f2
!tmp1

Finally, combining both parameters (-x*\f2 -x*\a), you get this:

!tmp1\f1\f1.txt
!tmp1\f1
!tmp1
Eventuate answered 2/5, 2015 at 20:13 Comment(0)
E
2

To manage large list of files to be excluded, you can create text fie and write all excluded files/folders relative to the source folder:

1) create file list.txt, write the name of excluded files/folders note: * refer to the source, all files/folders are relative to the source folder

*\f2 *\f3

2) Run the command

       rar a -r  [email protected] target.rar source-folder
Endodermis answered 4/12, 2018 at 2:17 Comment(0)
S
1

It's as simple as this: Right click on the folder you want to compress, select "add to archive", in the little dialog window that opens go to the "Files" tab and enter the folder names you want to exclude in the "Files to exclude" field like this: Imagine you want to exclude all the folders named "styles" in your compression, you enter this:

*styles/

Common example for node.js programmers: You want to exclude the "node_modules" folder? just enter this in the Files to exclude field:

*node_modules/

You can add other stuff to exclude just by separating them by a space. Example:

*node_modules/ *dist/ *.txt

Schoolmaster answered 26/5 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.