Padding single digit date with zero

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Padding single digit date with zero

Postby Thaumaturge » Wed Jan 26, 2022 11:26 pm

Hi. This may be one of many queries as i have been putting some manners on an archive of around 650 top of the pops episodes which are absolutely mangled name/format wise.

The batch i'm trying to fix atm are in single digit date format so i'd like to add a zero for digits under 10. File format atm is:

Top of the Pops 6-8-81.vob

I came across the java script below suggested for adding the 0



function prependZero(number) {
if (number < 9)
return "0" + number;
else
return number;
}


However when i put that into the special (14) box for javascript it doesn't do anything to the filename. Am i doing something wrong or does the code not work with BRU?


TIA
Thaumaturge
 
Posts: 9
Joined: Wed Nov 17, 2021 7:35 am

Re: Padding single digit date with zero

Postby Admin » Thu Jan 27, 2022 1:22 am

Hi, can you post some examples of names before and after rename? thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Padding single digit date with zero

Postby Thaumaturge » Thu Jan 27, 2022 1:41 am

Hi..

As i say, the script isn't doing anything when i add it but the effect i'm looking for is to change the likes of these:

Top of the Pops 1-12-79
Top of the Pops 22-5-79

to

Top of the Pops 01-12-79
Top of the Pops 22-05-79


There are other steps but this is the only adjustment i can't achieve with the apps i have already


thanks
Thaumaturge
 
Posts: 9
Joined: Wed Nov 17, 2021 7:35 am

Re: Padding single digit date with zero

Postby Admin » Thu Jan 27, 2022 3:54 am

To make it easier, you could just replace
1- with 01-
2- with 02-
3- with 03-
4- with 04-
5- with 05-

up to 9.

The Javascript function you have does not contain newName changes so it will not change the name.
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Padding single digit date with zero

Postby Thaumaturge » Thu Jan 27, 2022 4:11 am

Would that not also pad the already dbl digit parts.. eg 01-6-79 becomes 001-6-79?

Normally i do try to make these changes as you suggest with find/replace but i've yet to find an app that will let me define custom loadable lists of preset replace rules to apply as the need requires. Flash Renamer for example only keeps the one list of presets so after a point your rules all start clashing. Is it possible in BRU?
Thaumaturge
 
Posts: 9
Joined: Wed Nov 17, 2021 7:35 am

Re: Padding single digit date with zero

Postby Admin » Thu Jan 27, 2022 5:27 am

You could use

<space>1- with 01-
<space>2- with 02-
etc

for the days

and

-1- with 01-
-2- with 02-
etc

for the months.


You can use character translations in BRU to save the replacement lists:
viewtopic.php?f=12&t=1329

Or use the Replace function in BRU Replace (3) which supports multiple replacements separated by a | (See the help file for more info)

All the settings can be saved to a file and reloaded as needed in BRU.
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Padding single digit date with zero

Postby Thaumaturge » Thu Jan 27, 2022 7:19 am

Thanks for all that.. good to have both options there... however

I went with custom replace (3) lists that i can save as txt and reuse. It seemed to work ok on one batch of files but then not another larger batch. My presets were

REPLACE

1-| 2-| 3-| 4-| 5-| 5-| 7-| 8-| 9-|-1-|-2-|-3-|-4-|-5-|-6-|-7-|-8-|-9-

WITH

01-| 02-| 03-| 04-| 05-| 05-| 07-| 08-| 09-|-01-|-02-|-03-|-04-|-05-|-06-|-07-|-08-|-09-


If you see the screenshot below it doesn't seem to be doing what it should on the loaded files


https://ptpimg.me/9l9n65.jpg


Any idea why?

TIA
Thaumaturge
 
Posts: 9
Joined: Wed Nov 17, 2021 7:35 am

Re: Padding single digit date with zero

Postby Thaumaturge » Thu Jan 27, 2022 7:32 am

Edit:

i fixed the error in that preset (5 done twice) and it seems to be padding the first part of the date correctly but not the middle

https://ptpimg.me/260271.png
Thaumaturge
 
Posts: 9
Joined: Wed Nov 17, 2021 7:35 am

Re: Padding single digit date with zero

Postby Admin » Fri Jan 28, 2022 1:54 am

I think it is only matching one string at a time, so you might need 2 passes (two renames).
The character translations might do it in one pass.
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Padding single digit date with zero

Postby Thaumaturge » Fri Jan 28, 2022 5:08 am

Seems to have the same problem.
https://ptpimg.me/uw9clf.png
Thaumaturge
 
Posts: 9
Joined: Wed Nov 17, 2021 7:35 am

Re: Padding single digit date with zero

Postby Luuk » Fri Jan 28, 2022 4:04 pm

With the javascript, can also try some codes like...
if (name.endsWith(/ \d{1,2}-\d{1,2}-\d\d/)) {
date=name.replace(/.* (.*)/, '$1')
padded=date.replace(/\b(\d)\b/g, '0$1')
newName=name.replace(/(.* ).*/, '$1') + padded }

Also RegEx(1) might be good enough with a checkmark in "v2" and a "Match" and "Replace" like...
\b(\d)(?=-\d)/g
0$1
Luuk
 
Posts: 692
Joined: Fri Feb 21, 2020 10:58 pm

Re: Padding single digit date with zero

Postby Thaumaturge » Fri Jan 28, 2022 11:35 pm

Thanks but all that code is just beyond me. I've ended up doing it in two passes as suggested though it's a shame it didn't seem to allow multiple operations in a single set of rules..
Thaumaturge
 
Posts: 9
Joined: Wed Nov 17, 2021 7:35 am

Prefix zero to variable, if its a single digit 1-9

Postby Luuk » Mon Feb 14, 2022 10:32 pm

Without seeing the code for "getformatteddate task" or the filenames, its not possible to give complete answer.
One way to test variable for any single digit 1-9, so to then prefix a zero ...
if (/^[1-9]$/.test(variable)) {variable = '0' + variable};
Luuk
 
Posts: 692
Joined: Fri Feb 21, 2020 10:58 pm

Re: Padding single digit date with zero

Postby Luuk » Tue Feb 15, 2022 7:23 pm

This code that you are posting, was first posted by Thaumaturge on Jan 26.
But I'm already give two different methods for padding his dates the first time.

The code that he copied and pasted from another website, will only conduct one-variable called "number".
To use his pasted code, you would first create this variable, so that it can hold the proper date-elements.
Then you would have to modify the variable "newName" like Admin says, to include those padded results.

But without filename examples, it will be impossible to advise.
Luuk
 
Posts: 692
Joined: Fri Feb 21, 2020 10:58 pm


Return to Javascript Renaming