The Crop function help

Post any Bulk Rename Utility support requirements here. Open to all registered users.

The Crop function help

Postby testusetom » Sat Sep 03, 2016 12:42 am

Hi,

This post might be a bit long so bear with me.

I've been using BRU to rename thousands of files in the past. Really loving this utility so far. The files have a format like this:
[Tag] Title of files - 00 (0000x00 00abc abc) [2FA8U407].ext
where the [Tag], Title of files, (0000x00 00abc abc) and [2FA8U407] may vary in length with either characters, numbers and spaces.

In the past I've always been lazy and used the remove First n and last n to get results like:
Title of files - 00.ext

However as I've been dealing with an increase amount of files formatted like this (different folders have different length of [Tags] and [#HASH]), I finally got my self to read the manual and discovered the "crop" function. With the special mode selected, I could enter [*], however, the files would end up like this:
Title of files - 00 (0000x00 00abc abc) [2FA8U407].ext
Instead of cropping out all the [*], it simply removed the first one only. In addition I need to also remove (*), making this function essentially impracticable due to the fact it only accepts one parameter and doesn't even remove all brackets matching the parameter.

After this, I discovered RegEx. However, after reading the documentary and fiddling with the program, I still couldn't understand how to use it. I'm sure it's the solution to my problem, but unfortunately I couldn't figure out how to get it to work.

I'm pretty lost now, and I'm not too sure what to do now aside from writing this thread for some insight.

On the side not, I actually considered using the CLI version, so I could write a script to remove [*], [*], (*) with 3 lines removing each of them once, only to realize after I downloaded the CLI utility that it doesn't support the crop fuction :(
testusetom
 
Posts: 5
Joined: Fri Sep 02, 2016 3:56 pm

Re: The Crop function help

Postby FileMangler » Sat Sep 03, 2016 10:16 pm

Not sure if this meets all your scenarios - see screenshot - :x :x can't find a way to upload images, so anyway, try this:
in the first field RegEx (1), enter this:
Code: Select all
Match:   ^(.*?])([\w\s-]*)(\(.*)$
Replace:   \2

In the 5th field Remove (5), enable the checkbox "Trim"
What the 5th step will do = remove leading and trailing spaces that may be left over after the first step (the RegEx)

What the first step will do = break up your file name into 3 very basic parts:
^(.*?]) = front part, containing everything up to (and including) the first closing bracket "]" that comes along
(\(.*)$ = end part, starting from (including) the first opening parenthesis "(" that comes along, til the end
([\w\s-]*) = middle part = the part you're interesting in (provided it does NOT contain a bracket or parenthesis)

This middle part is the only part you are interested in, which is why it's the only part you keep in Replace = \2
FileMangler
 
Posts: 9
Joined: Sun Aug 07, 2016 11:19 pm

Re: The Crop function help

Postby therube » Sun Sep 04, 2016 3:04 pm

5:Remove -> Crop: Special, [*]

Note that, (*] can help out too.

If you were to rename your files (& yes, it only removes the first instance), then uncheck the checkbox for 5:Remove, then recheck it, then Rename, that would then remove the second instance. Repeat... for as many times as you need.
(Not exactly convenient, but depending, it might only take a few check/recheck/rename operations to complete.)


I need to also remove (*), making this function essentially impracticable due to the fact it only accepts one parameter and doesn't even remove all brackets matching the parameter.

Not quit following that?
(Or are you saying, not only bracket*bracket items, but paren*paren items to?)
Oops, yes you do.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: The Crop function help

Postby testusetom » Sun Sep 04, 2016 3:21 pm

FileMangler wrote:Not sure if this meets all your scenarios - see screenshot - :x :x can't find a way to upload images, so anyway, try this:
in the first field RegEx (1), enter this:
Code: Select all
Match:   ^(.*?])([\w\s-]*)(\(.*)$
Replace:   \2



Hi,

Thanks! This actually works very well, and I'm starting to understand how it works.

However, after using it for a whole I found that I had some files that used multiple brackets at the end, while others also used parenthesis.
EDIT: To clarify, files are like "...(*)[*].ext" usually but some look like "...[*][*].ext" for some reason, while rarely some look like "...[*](*)[*].ext".
I modified the original code from
Code: Select all
^(.*?])([\w\s-]*)(\(.*)$

to

^(.*?])([\w\s-]*)(\[.*)$


However, this leaved files with parenthesis in them untouched. I next discovered by changing the code to
Code: Select all
^(.*?])([\w\s-]*)(.*)$

This actually removes either parenthesis and brackets at the end, but I'm not sure what the drawbacks are to this code...?

In addition, a very few selection of my files also have special characters in them. Is it possible to let ([\w\s-]*) know to ignore all special characters except parenthesis or brackets? Also, what does [\w\s] mean? I was only able to find these in the documentary:

    * Matches the previous character zero or more times
    + Matches the previous character one or more times
    ? Matches the previous character zero or one times
    . Matches any single character except the newline
    ^ Matches the start of the input
    $ Matches the end of the input
    x|y Matches either first or second character listed
    (pattern) Matches pattern
    {number} Matches exactly number times
    {number,} Matches number, or more, times (note comma)
    {num1, num2} Matches at least num1 and at most num2 times
    [abc] Matches any character listed between the [ ]
    [^abc] Matches all characters except those listed between the
    [ ]
    [a-e] Matches any characters in the specified range (a,b,c,d,e)
    [^K-Q] Matches all characters except in the specified range
    \ Signifies that the next character is special or a literal.
    \b Matches only on a word boundary
    \B Matches only inside a word
    \f Matches only on a form feed character
    \n Matches only on a new line
    \r Matches only on a carriage return
    \s Matches only on a blank space
    \S Matches only on nonblank spaces
    \t Matches only on a tab
    \d Matches any digit


On the side note, I'm surprised this forum has no [spoiler] code to hide messy copy paste jobs.
Last edited by testusetom on Sun Sep 04, 2016 3:35 pm, edited 1 time in total.
testusetom
 
Posts: 5
Joined: Fri Sep 02, 2016 3:56 pm

Re: The Crop function help

Postby testusetom » Sun Sep 04, 2016 3:28 pm

therube wrote:5:Remove -> Crop: Special, [*]

Note that, (*] can help out too.

If you were to rename your files (& yes, it only removes the first instance), then uncheck the checkbox for 5:Remove, then recheck it, then Rename, that would then remove the second instance. Repeat... for as many times as you need.
(Not exactly convenient, but depending, it might only take a few check/recheck/rename operations to complete.)


Thanks for the first tip! Didn't know you could do (*].

However, this makes it rather inconvenient, and I also stated I actually meant to get around this by writing a bat script using the CLI, only to find it doesn't support the crop - special function.
testusetom
 
Posts: 5
Joined: Fri Sep 02, 2016 3:56 pm

Re: The Crop function help

Postby FileMangler » Mon Sep 05, 2016 10:20 am

Not sure if there is a drawback to your approach. I actually like it better than mine, less complicated.

I am by no means an expert in RegEx, still struggling to come to terms with the help resources.
Many of the links provided here in the forum point to RegEx flavors that don't apply to BulkRename. Very confusing and frustrating.
If only I knew what RegEx flavor the BRU engine uses - if you know more about that, I'd greatly appreciate it.

Back to your case:
\w "normally" means any character A-Z and a-z and 0-9 and underscore, but I am not sure if that applies to BRU unconditionally, especially in respect to Unicode characters. Sometimes I get a pattern to work in Autohotkey, but not in BRU.
\s means any space, meaning white space. Again, I am not sure if the BRU flavor includes Tab and whatever else there might be, or just the space character.
testusetom wrote:. Is it possible to let ([\w\s-]*) know to ignore all special characters except parenthesis or brackets?

You mean to catch everything except for brackets and parentheses?
([^][()]*) for the middle group should to the trick
If your middle part ALWAYS ends on "hyphen + 2 digits exactly" you might specify this, to make it safer and more reliable:
Code: Select all
([^][()]*- \d\d)

This allows your middle part to contain anything - $ % & ? = " ! - but not brackets and not parentheses
Breaking it down - from the outside-in and right to left:
(....) = group for backreferencing this middle part
- \d\d = hyphen + space + any digit + any digit
* = zero or more of whatever comes right before the *
[...] = a list of characters
^ = NOT when used inside [.....] - in other words: [^][()] means "any one character but NOT ] [ ( )"
FileMangler
 
Posts: 9
Joined: Sun Aug 07, 2016 11:19 pm

Re: The Crop function help

Postby testusetom » Tue Sep 06, 2016 1:54 am

FileMangler wrote:\
([^][()]*) for the middle group should to the trick


Thanks! Unfortunately some files to go up to 3 digits, so i couldn't use the "*- /d/d". However, "([^][()]*)" did the trick to me, and upon further test it suits all the scenarios (for now).

Again, thanks for the help! I really appreciate it!
testusetom
 
Posts: 5
Joined: Fri Sep 02, 2016 3:56 pm

Re: The Crop function help

Postby FileMangler » Tue Sep 06, 2016 5:38 am

You're welcome.
testusetom wrote:some files to go up to 3 digits, so i couldn't use the "*- /d/d".

([^][()]*- \d{2,3} allows the \d (digit) to repeat between 2 and 3 times, but not more than 3. Note the braces (not brackets)
FileMangler
 
Posts: 9
Joined: Sun Aug 07, 2016 11:19 pm


Return to BRU Support