Convert Months into numbers?

Bulk Rename Utility How-To's

Convert Months into numbers?

Postby amazing » Sun Aug 08, 2021 4:47 am

Image
Taking this as example, How do I rename them in numbers, and only take the shortened version of the year instead of 4 digits?
E.g.
21-04 Market Analysis
...
21-05 Market Analysis
amazing
 
Posts: 12
Joined: Sat Jul 31, 2021 4:38 am

Re: Convert Months into numbers?

Postby Luuk » Sun Aug 08, 2021 12:02 pm

There is many ways to convert both of the month-names and month-abbreviations into their month-numbers.
But if only wanting to conduct filenames like inside of the screenshot, then RegEx(1) is to be the best solution.

First inside of the Filters(12) to put a 'Mask' like *.pdf so then clicking the blue-arrows beside 'Mask' will conduct this filter.
Inside RegEx(1) to put a checkmark in "v2", so this grants using (?X) to say 'Next-Match' or 'Next-Replace', so then its a 'Match' and 'Replace' like...

^(Market Analysis) ([^ ]+ )20(\d\d)( \([^)]+\))?$(?X):Jan(uary)?(?X):Feb(ruary)?(?X):Mar(ch)?(?X):Apr(il)?(?X):May(?X):June?(?X):July?(?X):Aug(ust)?(?X):Sep(tember)?(?X):Oct(ober)?(?X):Nov(ember)?(?X):Dec(ember)?
$3-:$2$1(?X)01(?X)02(?X)03(?X)04(?X)05(?X)06(?X)07(?X)08(?X)09(?X)10(?X)11(?X)12

If you need to match your months better, because some names dont have a month, change ([^ ]+ ) into something more like...
((?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?) )
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Convert Months into numbers?

Postby amazing » Mon Aug 09, 2021 3:43 am

Thanks again! I'm trying to DIY on another set of files here. Why is it that my regex doesn't work?

Image
amazing
 
Posts: 12
Joined: Sat Jul 31, 2021 4:38 am

Re: Convert Months into numbers?

Postby Luuk » Mon Aug 09, 2021 12:23 pm

Its just because " ([^ ]+ )" looks for "1-or-more non-spaces inbetween two spaces", so that group is not needed for these filenames.
I used ([^ ]+ ) as a shortcut for month names/abbreviations, only because the better month-matcher (at the bottom) was so very long.
And the match was already getting too long to fit onto just 1-line, so then Im just making it with smaller fonts, and with the shortcut.

You could change the "v2" expression by editing ([^ ]+ )20 ===> (\d\d-\d\d-|[^ ]+ )2?0? and using Replace(3) to destroy ':' .
This could let you conduct both formats all at the same time, except that Im not knowing.. What to do with the days?
Im guessing that you always like to keep the days, because \d\d being inside of the parenthesis.

For myself, Im always wanting dates to be in the same format, so Im often use '00' to say 'missing days'.
But then, you would have to edit all of your "v2" replacements like... (?X)01-00(?X)02-00(?X)03-00(?X).

If all of your filenames have either: month-names, month-abbreviations, or month-numbers, like inside of the screenshots?
Then its ok making this "v2" edit to conduct them all, but otherwise must include the very long month-matcher at the bottom.
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Convert Months into numbers?

Postby Admin » Mon Aug 09, 2021 1:09 pm

An alternative method is to rearrange positions inside the file names using Regex with "Simple" flag and then replace month names and year (character translation can also be used for that).
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To


cron