12

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.

Mark Robbins
  • 2,302
  • 2
  • 22
  • 32
  • 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`? – Wug Aug 21 '12 at 21:13
  • 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. – Mark Robbins Aug 21 '12 at 22:25
  • @MarkRobbins, could you ever solve this issue? Could you try my solution? – Andrew Apr 01 '16 at 13:21

3 Answers3

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.

codisfy
  • 2,095
  • 2
  • 20
  • 31
7

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
Andrew
  • 6,492
  • 2
  • 29
  • 38
1

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  -x@list.txt target.rar source-folder
M.Hassan
  • 7,947
  • 4
  • 45
  • 67