identifying sets of files by number

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

identifying sets of files by number

Postby Stoobs » Mon May 09, 2022 4:54 am

Here's an example of what I'm trying to do.

I'd have files with names like these (parts of names really):

Folder_One
leg_01
leg_02
leg_03
arm_01
arm_02

Folder_Two
elbow_01
arm_01

All files with the same number in the same folder are part of a set, and should have a matching name.

(eg. leg_01, arm_01, and elbow_01 become leg_antelope, arm_antelope, elbow_chameleon -- arm_01 in Folder_Two would become arm_chameleon) The names could be randomly generated or from a list.

My understanding is that the javascript runs once per file, but is there any way to save variables that persist? I'm new to BRU and a Javascript novice, so I'm not sure what the capabilities are.

I'm not expecting full code or anything, but if someone can point me in the right direction I'd appreciate it.

Thanks (I hope this makes sense!)
Stoobs
 
Posts: 2
Joined: Thu May 05, 2022 10:35 pm

Change replacements per folder-name

Postby Luuk » Mon May 09, 2022 9:38 am

The variables do always reset after conducting each file, so their values cannot be saved to conduct against the next file.
One way could be making a folder-list, then using if statements to compare folder-names with their separate-lists like...

str=name

if (/.*\\Folder_One\\$/.test(object('folder'))) {
str=str.replace(/_01/g, '_antelope')
str=str.replace(/_02/g, '_cat')
str=str.replace(/_03/g, '_dog')}

if (/.*\\Folder_Two\\$/.test(object('folder'))) {
str=str.replace(/_01/g, '_chameleon')
str=str.replace(/_02/g, '_elephant')
str=str.replace(/_03/g, '_tiger')}

newName=str
Luuk
 
Posts: 771
Joined: Fri Feb 21, 2020 10:58 pm

Re: identifying sets of files by number

Postby Stoobs » Tue May 10, 2022 8:57 pm

That might work, thanks.
Stoobs
 
Posts: 2
Joined: Thu May 05, 2022 10:35 pm


Return to Javascript Renaming