How to change name every x files?

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

How to change name every x files?

Postby djpalmis » Sat Dec 11, 2021 6:25 pm

Introduction:
I have a personal licence, I found this program while googling for my issue: I hope I can use javascrit.

So i have a list of files whose name are like:
[000277].mp4
[000278].mp4
[000279].mp4
[000280].mp4
[000281].mp4
[000282].mp4

I need to change the name following a pattern like:
The first one is the back, the second one is the left, 3* right and 4* front.
And i need a timestamp (i don't care about time, but i need it is different every 4 files.
ok?
So I need to change the name from that list to the following:
2021-12-07_15-24-40-back.mp4
2021-12-07_15-24-40-front.mp4
2021-12-07_15-24-40-left_repeater.mp4
2021-12-07_15-24-40-right_repeater.mp4
and then again, 1 minute later
2021-12-07_15-25-40-back.mp4
and so on.

Question is: Can I enumerate the file list so i can rename by a defined pattern?
djpalmis
 
Posts: 1
Joined: Sat Dec 11, 2021 6:08 pm

Re: How to change name every x files?

Postby Luuk » Sun Dec 19, 2021 1:05 am

If only wanting to conduct .mp4-files that have numbers inside of the brackets??
Filters(12) needs a checkmark inside for 'RegEx' so then a 'Mask' like... ^\[\d+\]\.mp4$
Then the javascript can be something like...

xx = new Date(2021,11,7,15,24,40)
xx.setMinutes(xx.getMinutes()+(counter/4)-.01)
// ===== Formatting date elements =====
yr = xx.getFullYear() + '-'
mo = ("0"+(xx.getMonth()+1)).slice(-2) + '-'
dy = ("0"+(xx.getDate())).slice(-2) + '_'
hr = ("0"+(xx.getHours())).slice(-2) + '-'
mi = ("0"+(xx.getMinutes())).slice(-2) + '-'
se = ("0"+(xx.getSeconds())).slice(-2)
// ===== Letting math decide for the NewNames =====
if (counter%4==1) {newName = yr+mo+dy+hr+mi+se+'-back'}
if (counter%4==2) {newName = yr+mo+dy+hr+mi+se+'-front'}
if (counter%4==3) {newName = yr+mo+dy+hr+mi+se+'-left_repeater'}
if (counter%4==0) {newName = yr+mo+dy+hr+mi+se+'-right_repeater'}

This does increment 1-minute for each 4 matched-files, and you can also change the starting date.
But '11' will say 'December', or you could say it like... xx = new Date("December 7 2021 15:24:40")
Luuk
 
Posts: 692
Joined: Fri Feb 21, 2020 10:58 pm


Return to Javascript Renaming