Skip to main content
Known Participant
March 2, 2022
Answered

Rename multiple files

  • March 2, 2022
  • 2 replies
  • 5117 views

Hi guys.

I need to rename a lot of files sequentially that have a pattern like:

 

keep the filename, but change the 5 digits to single digits: 

 

AJKGHD-BK-76357.jpg

AJKGHD-BK-76358.jpg

AJKGHD-BK-76359.jpg

to

AJKGHD-BK-1.jpg

AJKGHD-BK-2.jpg

AJKGHD-BK-3.jpg

and or

KGH-WH-36286.jpg

KGH-WH-36287.jpg

KGH-WH-36288.jpg

to

KGH-WH-1.jpg

KGH-WH-2.jpg

KGH-WH-3.jpg

 

Hope that makes sense. Any help is appreciated. Thank you 

This topic has been closed for replies.
Correct answer Kukurykus

 

objct = {}, File('~/desktop/folder')
.getFiles(function(v){k0 = (key = decodeURI(v.name)
.split(/\d+/))[0], v.rename(k0 + eval('objct[k0] '
+ ({1: '', 0: '+'})[+!objct[k0]] + '= 1') + key[1])})

 

2 replies

Kukurykus
KukurykusCorrect answer
Legend
March 2, 2022

 

objct = {}, File('~/desktop/folder')
.getFiles(function(v){k0 = (key = decodeURI(v.name)
.split(/\d+/))[0], v.rename(k0 + eval('objct[k0] '
+ ({1: '', 0: '+'})[+!objct[k0]] + '= 1') + key[1])})

 

Known Participant
March 2, 2022

@Kukurykus is this a javascript that I can use in bridge ? 

Kukurykus
Legend
March 2, 2022

This is cross Adobe applications ExtendScript code. For Bridge use this line as first:

 

#target bridge

 

 

Stephen Marsh
Community Expert
Community Expert
March 2, 2022

@Adrian22725754sr2n 

 

Here is one way:

 

 

Regular Expression Find: (.+-)(\d+)

Regular Expression Replace: $1

 

And another one, different but same:

 

 

Regular Expression Find: (.+-)(\d+)(\.[^\.]+$)

Regular Expression Replace: $1

 

Notes:

  • Don’t use a single-digit sequence number if there are more than 9 files being renamed
  • Although not shown above, it is generally a good idea to tick the "Preserve current filename..." checkbox
  • Always use the "Preview" button on the right-hand side of the interface to preview all selected files
  • When renaming in batches, the next batch will use the next sequential number, so this may need to be reset to 1 for each batch as long as this will not create duplicate filenames

 

Known Participant
March 2, 2022

Thank you @Stephen Marsh 

 

I tried but I'm facing a problem now...reseting that number 1 every batch...i can't do that...

 

all my files are in the same folder...so when I rename : 

AJKGHD-BK-76357.jpg

AJKGHD-BK-76358.jpg

AJKGHD-BK-76359.jpg

to

AJKGHD-BK-1.jpg

AJKGHD-BK-2.jpg

AJKGHD-BK-3.jpg

 

the next files that are located in the same folder would be named : 

 

to

KGH-WH-5.jpg

KGH-WH-6.jpg

KGH-WH-7.jpg

 

but i need them to be named 1, 2, 3, 4

Stephen Marsh
Community Expert
Community Expert
March 2, 2022

My javascript is not my strongest part. I'm a photographer. I have already few scripts installed and working very good. The only problem is that they use Regex which I will never understand...

 

- I would restart the sequence number based on filename, exactly. If only possible of course. 

- Not every 3 files are another batch...it will vary...could be 2, 3, 4, 5, 6 max would be i guess 7 

- all the files are in a single directory, yes. 

 

Thank you again ! 

 


Regex is easier than the scripting!

 

If you have a batch JSX file for renaming that works, but you just need the regex changed, that should be easy enough, however, things are never that easy are they?

 

A more comprehensive list of filename pattern samples than previously provided would be required for the regex.

 

This is very likely beyond my ability, however, there are a number of others on the Photoshop and Bridge forums that could script this.