Skip to main content
Known Participant
Mar 2, 2022 9:51 AM UTC
Answered

Rename multiple files

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 is closed to new replies. Start a new post to keep the conversation going.
Kukurykus
KukurykusCorrect answer
Legend
Mar 2, 2022 1:19 PM UTC

 

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])})

 

34 replies

Kukurykus
KukurykusCorrect answer
Legend
Mar 2, 2022 1:19 PM UTC

 

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])})

 

Translate
Known Participant
Mar 2, 2022 2:04 PM UTC

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

Translate
Kukurykus
Legend
Mar 2, 2022 2:14 PM UTC

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

 

#target bridge

 

 

Translate
Stephen Marsh
Community Expert
Community Expert
Mar 2, 2022 10:26 AM UTC

@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

 

Translate
Known Participant
Mar 2, 2022 10:43 AM UTC

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

Translate
Stephen Marsh
Community Expert
Community Expert
Mar 2, 2022 10:56 AM UTC

I'm not seeing the problem? As long as there are no conflicts created by the new batch it should be fine to reset to 1 for each batch:

 

 

Translate