Naming based on numeric range

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

Naming based on numeric range

Postby madani426 » Sun Jul 21, 2024 6:25 am

Hello
I have a number of photos that I want to change according to the range of numbers
For example: if it is in the range of 1 to 7000, rename it to 0-0-95-7000.jpg
Or
If it is in the range of 70001 to 18000, change it to 0-0-96-18000.jpg
Or
If it is in the range of 18001 to 27000, change it to 0-0-97-27000.jpg
Or
.....
please guide me
Thanks
madani426
 
Posts: 3
Joined: Sun Jul 21, 2024 6:11 am

Different prefix for number-only-names by range

Postby Luuk » Mon Jul 22, 2024 1:32 am

An example could be like...
if (/^\d+$/.test(name)) {
if ((name) > 00000 && (name) <= 07000) newName= '0-0-95-' + name
if ((name) > 07000 && (name) <= 18000) newName= '0-0-96-' + name
if ((name) > 18000 && (name) <= 27000) newName= '0-0-97-' + name }

1 --------> 0-0-95-1
1999 ----> 0-0-95-1999
1999a --> (not renamed)
17000 ---> 0-0-96-17000
26000 ---> 0-0-97-26000
Luuk
 
Posts: 771
Joined: Fri Feb 21, 2020 10:58 pm

Re: Naming based on numeric range

Postby madani426 » Mon Jul 22, 2024 4:20 am

Thank you very much
But there is a problem
My file names are not just numbers
The beginning of the name is a number and then it is separated by a -
I want to write a formula that reads up to - number and then makes a comparison
Like the following numbers:
1428-3-c.jpg
4407-f2.jpg
4407-fff4.jpg
13999-f3.jpg
13999-f4.jpg
13999-fff4.jpg
78225-fff4.jpg
madani426
 
Posts: 3
Joined: Sun Jul 21, 2024 6:11 am

Re: Naming based on numeric range

Postby Admin » Mon Jul 22, 2024 4:40 am

The Javascript indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found. The indexOf() method is case sensitive.

var num = Number(name.substring(0, name.indexOf("-")));

This will put the number before '-' into the variable num which can then be used to apply conditional renaming.
Admin
Site Admin
 
Posts: 2641
Joined: Tue Mar 08, 2005 8:39 pm

Re: Naming based on numeric range

Postby madani426 » Mon Jul 22, 2024 4:59 am

Thank you very much for your guidance
The problem was solved
madani426
 
Posts: 3
Joined: Sun Jul 21, 2024 6:11 am


Return to Javascript Renaming