Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding folders in Winrar

Tags:

winrar

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.

like image 968
Mark Robbins Avatar asked Aug 21 '12 20:08

Mark Robbins


1 Answers

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
like image 184
Andrew Avatar answered Oct 30 '22 20:10

Andrew