Trying to change about 50,000 files at once (date transform)

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

Trying to change about 50,000 files at once (date transform)

Postby elyndar » Sat Mar 19, 2016 3:06 am

Hi,

I'm trying to figure out how to change a format of daymonthyear AA-### AA or daymonthyear AA-###-##.# AAA to AA-### AA Y_year M_month D_day. For example:

5JUL2001 FR-009 CAL > FR-009 CAL Y_2001 M_07 D_05
05JUN2013 FR-009-41.2 PM > FR-009-41.2 PM Y_2013 MON_06 D_05
01FEB2000 LQ-132 IMQ > LQ-132 IMQ Y_2000 M_02 D_01
01JUN2005 FR-009-41 IDX > FR-009-41 IDX Y_2005 M_06 D_01
1FEB2005 LBE-002-4 WO> LBE-002-4 WO Y_2005 M_02 D_01

I will eventually have a commercial licensed copy to do this with, but I'm trying to show proof that the program will do this to my boss so they will pay for the license. For now I have to use RegEx.
elyndar
 
Posts: 1
Joined: Sat Mar 19, 2016 2:47 am

Re: Trying to change about 50,000 files at once (date transform)

Postby Admin » Mon Mar 21, 2016 3:01 am

Hi, try this javascript function:

Code: Select all
n = name.indexOf(" ");
part1 = name.substr(0,n);
part2 = name.substr(n+1);
d = new Date();
d = Date.create(part1);
newName = part2 + ' ' + 'Y_' + d.getFullYear() + ' M_' + (d.getMonth()+1) + ' D_' + d.getDate();


You can preview the changes that would be applied even without a commercial license.

thanks
Admin
Site Admin
 
Posts: 1895
Joined: Tue Mar 08, 2005 8:39 pm

Re: Trying to change about 50,000 files at once (date transform)

Postby trm2 » Sat Feb 01, 2020 2:53 pm

Hello Admin.

The original poster wanted the format in MM DD but the JavaScript uses d.getMonth() which returns 0 -11 and 0-9 as D not DD. Same for d.getDate().

I modified the following to get the DD MM but where it fails is on the rearranging of the string to YYYY MM DD. It works on all samples except:

05JUN2013 FR-009-41.2 PM

It ends up with FR-009-41 Y_2013 M_06 D_05.2 PM not FR-009-41.2 PM Y_2013 M_06 D_05

Here is the modified code:

--------------------------------------------------------------------------------------
n = name.indexOf(" ");
part1 = name.substr(0,n);
part2 = name.substr(n+1);
d = new Date();
d = Date.create(part1);

var MM = ((d.getMonth() + 1) < 10 ? '0' : '') + (d.getMonth() + 1);
var dd = (d.getDate() < 10 ? '0' : '') + d.getDate();

newName = part2 + ' ' + 'Y_' + d.getFullYear() + ' M_' + MM + ' D_' + dd;

------------------------------------------------------------------------------------
I know it has something to do with the substring value.

Please assist.

Thank you.trm2
trm2
 
Posts: 155
Joined: Wed Jan 15, 2020 12:47 pm

Re: Trying to change about 50,000 files at once (date transform)

Postby Admin » Sun Feb 02, 2020 2:25 am

Hi, BRU thinks that .2 PM is the file extension and does not process it.
Admin
Site Admin
 
Posts: 1895
Joined: Tue Mar 08, 2005 8:39 pm

Re: Trying to change about 50,000 files at once (date transform)

Postby trm2 » Sun Feb 02, 2020 10:43 am

Of course. What a dolt. Too much writing late nights.

Thanks. Turning on the rename option did the trick.
trm2
 
Posts: 155
Joined: Wed Jan 15, 2020 12:47 pm


Return to Javascript Renaming