Rename title that contains month name to month number?

Bulk Rename Utility How-To's

Rename title that contains month name to month number?

Postby ado2207 » Sun Mar 15, 2020 7:19 pm

I have several PDFs that contain the month name in the title, for example: ABC_April_2019.pdf. How can I rename every instance of April to be 04? Same for all of the other months.
January=01
February=02
etc.
ado2207
 
Posts: 4
Joined: Sun Mar 15, 2020 7:15 pm

Re: Rename title that contains month name to month number?

Postby RegexNinja » Sun Mar 15, 2020 8:00 pm

The easiest way is to use #14 CharacterTranslations (manual at http://www.bulkrenameutility.co.uk/foru ... =12&t=4743)
Just paste this into it:

J,a,n,u,a,r,y=0,1
F,e,b,r,u,a,r,y=0,2
M,a,r,c,h=0,3
A,p,r,i,l=0,4
M,a,y=0,5
J,u,n,e=0,6
J,u,l,y=0,7
A,u,g,u,s,t=0,8
S,e,p,t,e,m,b,e,r=0,9
O,c,t,o,b,e,r=1,0
N,o,v,e,m,b,e,r=1,1
D,e,c,e,m,b,e,r=1,2

You might also want to use a #12Filter of *.pdf
Cheers!
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Rename title that contains month name to month number?

Postby ado2207 » Sun Mar 15, 2020 8:52 pm

Awesome, that's it. I was missing the commas. Thanks for the quick response.
ado2207
 
Posts: 4
Joined: Sun Mar 15, 2020 7:15 pm

Re: Rename title that contains month name to month number?

Postby therube » Sun Mar 15, 2020 9:05 pm

Nice.

Note, case sensitive.

Also you'd need to ensure that a "month name" is not being used otherwise.

Mayoral.race.txt -> 05oral.race.txt
therube
 
Posts: 998
Joined: Mon Jan 18, 2016 6:23 pm

Re: Rename title that contains month name to month number?

Postby Admin » Mon Mar 16, 2020 1:34 am

Include _ before / after the month to avoid Mayoral.race.txt -> 05oral.race.txt
Admin
Site Admin
 
Posts: 2041
Joined: Tue Mar 08, 2005 8:39 pm

Re: Rename title that contains month name to month number?

Postby RegexNinja » Mon Mar 16, 2020 6:15 am

Yes, if Month is always bordered like _Month_ (as shown in example).. a much better CharTrans:

_,J,a,n,u,a,r,y,_=_,0,1,_
_,F,e,b,r,u,a,r,y,_=_,0,2,_
_,M,a,r,c,h,_=_,0,3,_
_,A,p,r,i,l,_=_,0,4,_
_,M,a,y,_=_,0,5,_
_,J,u,n,e,_=_,0,6,_
_,J,u,l,y,_=_,0,7,_
_,A,u,g,u,s,t,_=_,0,8,_
_,S,e,p,t,e,m,b,e,r,_=_,0,9,_
_,O,c,t,o,b,e,r,_=_,1,0,_
_,N,o,v,e,m,b,e,r,_=_,1,1,_
_,D,e,c,e,m,b,e,r,_=_,1,2,_

Cheers to all!
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Rename title that contains month name to month number?

Postby ado2207 » Fri Mar 27, 2020 1:42 pm

How do I keep the character translations? Each time I restart the application, the list is cleared.

So far, the month is correctly renamed, but now I need to move it after the year. For example:

TitleA_-_April_2019.pdf converted to TitleA - 2019-04.pdf
TitleB_-_February_2020.pdf converted to TitleB - 2020-02.pdf

Is there a way to do this automatically just from the title? For each instance of ( _-_April_2019), convert it to ( - 2019-04), etc.?
ado2207
 
Posts: 4
Joined: Sun Mar 15, 2020 7:15 pm

Re: Rename title that contains month name to month number?

Postby RegexNinja » Fri Mar 27, 2020 4:34 pm

Hi,
I'm not sure what you mean about 'just from title', but regex can handle moving years.
Here is how I would handle it...

#12Filter with Regex=Checked (F5/Refresh if needed)
.*_-_.+_\d{4}\.pdf$

#1Regex Match/Replace:
^(.*?)_-(_[JFMASOND[a-z]{2,8}?[yhletr]_)(?!19[0-6])((19|20)\d{2})(?<!202[1-9]|20[3-9].)$
\1 - \3\2

14CharsTranslation:
_,J,a,n,u,a,r,y,_=-,0,1
_,F,e,b,r,u,a,r,y,_=-,0,2
_,M,a,r,c,h,_=-,0,3
_,A,p,r,i,l,_=-,0,4
_,M,a,y,_=-,0,5
_,J,u,n,e,_=-,0,6
_,J,u,l,y,_=-,0,7
_,A,u,g,u,s,t,_=-,0,8
_,S,e,p,t,e,m,b,e,r,_=-,0,9
_,O,c,t,o,b,e,r,_=-,1,0
_,N,o,v,e,m,b,e,r,_=-,1,1
_,D,e,c,e,m,b,e,r,_=-,1,2

Then use BRU's File/SaveAs and choose a name: something like FileMonthMover?
That way, all your options get saved, & you can retrieve them with BRU's File/Open command.

I tried to make the regex as specific as possible for your file formats..
Try it out to see if its specific enough.. If not, need more details on TitleA, etc
It will also only moves years from 1970-2020..

It works because #1Regex processes before CharTranlations
Regex purposely captures/moves _Month_ so that CharTrans can be more specific with its match.

So Regex does this: TitleA_-_Month_2019 -------> TitleA - 2019_Month_
CharsTrans this... : TitleA - 2019_Month_ -------> TitleA - 2019-##

Hope it helps.. Cheers!
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Rename title that contains month name to month number?

Postby ado2207 » Mon Mar 30, 2020 12:40 pm

That does the trick. But I also found that I have this format:

TitleA - April 2019.pdf

and in some cases there is the day of the month: TitleB - January 8, 2019.pdf

I tried to work with what was provided above and changed the _ to space, but I could not get it to pick up the titles that look like TitleA.
ado2207
 
Posts: 4
Joined: Sun Mar 15, 2020 7:15 pm

Re: Rename title that contains month name to month number?

Postby RegexNinja » Mon Mar 30, 2020 2:44 pm

Hi.. Here's a regex to handle all 3 conditions, using the same CharTranslation:

Notes:
[_ ] == UnderscoreOrSpace
( \d{1,2},){0,1} == SpaceAny2DigitsComma.. The 0 in {0,1} lets the group match nul/nothing, while 1 spec's a max-occurence.

#1Regex Match/Replace:
^(.*?)[_ ]-[_ ]([JFMASOND[a-z]{2,8}?[yhletr])( \d{1,2},){0,1}[_ ](?!19[0-6])((19|20)\d{2})(?<!202[1-9]|20[3-9].)$
\1 - \4_\2_

#14 CharTranslation:
_,J,a,n,u,a,r,y,_=-,0,1
_,F,e,b,r,u,a,r,y,_=-,0,2
_,M,a,r,c,h,_=-,0,3
_,A,p,r,i,l,_=-,0,4
_,M,a,y,_=-,0,5
_,J,u,n,e,_=-,0,6
_,J,u,l,y,_=-,0,7
_,A,u,g,u,s,t,_=-,0,8
_,S,e,p,t,e,m,b,e,r,_=-,0,9
_,O,c,t,o,b,e,r,_=-,1,0
_,N,o,v,e,m,b,e,r,_=-,1,1
_,D,e,c,e,m,b,e,r,_=-,1,2


Results:
TitleA - April 2019 ----------> TitleA - 2019-04
TitleB_-_April_2019 --------> TitleB - 2019-04
TitleC - January 8, 2019 ---> TitleC - 2019-01
TitleD_-_February_2020 ---> TitleD - 2020-02
((19|2
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Rename title that contains month name to month number?

Postby brunewb » Sun Jan 17, 2021 6:28 pm

Hello all -- I have followed this thread from Florida with interest, as I have 775 files with names similar to what Regex Ninja did for ado2207, and I have tried and tried to modify those conditions to match my particular filenames, and after two hours, I have accepted that I just suck at this. I'm hoping Regex Ninja will take pity on me and help me come up with a scheme that will do the trick for me.

My current filenames are variants on either:

JMM_September_24_2018.mp3
or
JMM_SA_January_22_2019.mp3

My goal is to convert all to the format:

JMM YYYY-MM-DD.mp3

The earliest file is January 2018 and the latest is January 2021.

When I try modifying Ninja's parameters, the day of the month disappears, or I can't get the underscore to go away, or any other number of kindergarten-level mistakes that make me feel like a dunce cap would be appropriate fashion attire.

I would be so grateful for any help.
brunewb
 
Posts: 2
Joined: Sun Jan 17, 2021 6:13 pm

Re: Rename title that contains month name to month number?

Postby brunewb » Sun Jan 17, 2021 6:56 pm

brunewb wrote:Hello all -- I have followed this thread from Florida with interest, as I have 775 files with names similar to what Regex Ninja did for ado2207, and I have tried and tried to modify those conditions to match my particular filenames, and after two hours, I have accepted that I just suck at this. I'm hoping Regex Ninja will take pity on me and help me come up with a scheme that will do the trick for me.

My current filenames are variants on either:

JMM_September_24_2018.mp3
or
JMM_SA_January_22_2019.mp3

My goal is to convert all to the format:

JMM YYYY-MM-DD.mp3

The earliest file is January 2018 and the latest is January 2021.

When I try modifying Ninja's parameters, the day of the month disappears, or I can't get the underscore to go away, or any other number of kindergarten-level mistakes that make me feel like a dunce cap would be appropriate fashion attire.

I would be so grateful for any help.



EDIT: I wanted to clarify my descriptions of the original filenames. They're some variant of:

JMM_MM_DD_YYYY.mp3
or
JMM_SA_MM_DD_YYYY.mp3

and the goal is to rename all as: JMM YYYY-MM-DD.mp3.

Thanks again!
brunewb
 
Posts: 2
Joined: Sun Jan 17, 2021 6:13 pm

Re: Rename title that contains month name to month number?

Postby Luuk » Mon Jan 18, 2021 9:00 pm

Greetings Brunaweb, Im not understanding the variant for filenames, but just answered two questions almost exactly like this, except that Im using the checkmark in "v2", so maybe to do the experiments with match and replace like...
JMM%1_%2_%3_%4
JMM%1 %4-%2-%3
The "JMM%1" does hold everything before the very last three underscores, if this to be good enough.
Luuk
 
Posts: 241
Joined: Fri Feb 21, 2020 10:58 pm


Return to How-To