• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Rename multiple files

Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

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 

TOPICS
Scripting

Views

595

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 02, 2022 Mar 02, 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])})

 

Likes

Translate

Translate
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

@Adrian22725754sr2n 

 

Here is one way:

 

rename1.png

 

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

Regular Expression Replace: $1

 

And another one, different but same:

 

rename2.png

 

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Thank you @Stephen_A_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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

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:

 

batch1.png

 

batch2.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

well when you just select the files separately yeah....that would work...

i have hundred of batches...selecting them separately would take me forever 😞 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Bridge isn't the only file-renaming utility out there, but I'm not sure how the sequence numbering would be reset to 1 for each "batch". Some sort of rule/pattern match would be required.

 

If you are proficient with spreadsheets, then you can split and combine the filenames to create a command line code for the command line prompt in either Mac or Win OS to rename files.

 

Presuming that the command prompt is in the appropriate directory...

 

Mac:

mv 'AJKGHD-BK-76357.jpg' 'AJKGHD-BK-1.jpg'
mv 'AJKGHD-BK-76358.jpg' 'AJKGHD-BK-2.jpg'
mv 'AJKGHD-BK-76359.jpg' 'AJKGHD-BK-3.jpg'
mv 'KGH-WH-36286.jpg' 'KGH-WH-1.jpg'
mv 'KGH-WH-36287.jpg' 'KGH-WH-2.jpg'
mv 'KGH-WH-36288.jpg' 'KGH-WH-3.jpg'

 

Win:

ren "AJKGHD-BK-76357.jpg" "AJKGHD-BK-1.jpg"
ren "AJKGHD-BK-76358.jpg" "AJKGHD-BK-2.jpg"
ren "AJKGHD-BK-76359.jpg" "AJKGHD-BK-3.jpg"
ren "KGH-WH-36286.jpg" "KGH-WH-1.jpg"
ren "KGH-WH-36287.jpg" "KGH-WH-2.jpg"
ren "KGH-WH-36288.jpg" "KGH-WH-3.jpg"

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh  I appreciate your effort but i was thinking javascript can do this so I can integrate it as a script shortcut...

please don't get me wrong. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

I'm sure it could be scripted.

 

How are you with JavaScript? There are fewer people proficient with Bridge scripting than say Photoshop. This could be scripted in Photoshop as well.

 

How would you set the rule/pattern for stopping and restarting the sequence numbering to 1 for each batch? 

 

Would it be based on filename sort?

 

Would it be as simple as every 3 files is a batch?

 

Are all the files in a single directory, or is each batch in sub-directories?

 

 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

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 ! 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Can't thank you enough @Stephen_A_Marsh  ! 

 

#target bridge     
if( BridgeTalk.appName == "bridge" ) {    
var cSelected = new MenuElement("command", "Rename family",  "at the end of Tools","cFiles");  
}  
cSelected.onSelect = function () {  
var sels = app.document.selections;  
var count = app.document.selectionsLength;  
for(var a =0;a<count;a++){  
var newName =decodeURI(app.document.selections[a].spec.name).match(/[^-]*/);  
var ext = decodeURI(app.document.selections[a].spec.name).match(/\..+$/);  
app.document.selections[a].spec.copy(app.document.presentationPath+ "/" +newName+"-1"+ext);  
    }  
}; 

This is the script I use a lot...in bridge

what it does is : 

GFHJGF-OR-1.jpg turns into GFHJGF-1.jpg 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

 

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

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

 

#target bridge

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

i tried to install it and getting this error 😞 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

This is not the script to run by putting it in StartupScripts folder. Move some of your files to location I used in the script for a test, and run script directly running it when Br is launched. When it does the job change path in code to yours, so that where you keep the files to process.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Perhaps @Kukurykus could provide more detailed instructions on how to run the script in Bridge without installing it as a startup script? I am not sure how that is done... What I did is use MS Visual Code ExtendScript Debugger to target the running version of Bridge to run/debug the script. On Windows, one could use the old ESTK app. I wouldn't expect anybody that was not into script development to have to do the above.

 

As the script is cross-application, it also works by simply going to Photoshop's File > Scripts > Browse... menu item.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

With made update I mentioned in previous post you click twice on Windows the file which asks if you want to open the Bridge if not open yet, then it does a job, so changes files names.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Ah, I see, I have never run a script from Bridge that was not a startup script, I didn't even know that it was possible.

 

It works on the Mac too, as I have .jsx files associated with MS Visual Studio Code, I had to right-click and select "open with...." and then browse to the Bridge.app file and it then worked as expected. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Or else .jsx dragged to Bridge will work too, so like you can do for Photoshop.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

@Adrian22725754sr2n 

 

So, how did you go with the script now that you know how to successfully run it from either Bridge or Photoshop?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 16, 2022 Mar 16, 2022

Copy link to clipboard

Copied

I have it on my Desktop...it's working great but my folder name changes all the time

I export my files to dropbox so every shooting i have a different folder name....i have to get that folder name and update the script .... 

 

I wish i can turn it into a bridge shortcut....so when I'm inside bridge hit cmd+F8 or something and the files are renamed...maybe somebody can help me with that....

 

Thank you @Kukurykus  and @Stephen_A_Marsh  you guys are very helpful all the time I come up with questions ! 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2022 Mar 16, 2022

Copy link to clipboard

Copied

@Adrian22725754sr2n 

 

Please mark the reply from Kukurykus as correct then.

 

You can try this top-level folder selection code addition for Photoshop (doesn't work in Bridge):

 

 

#target photoshop
objct = {}, dir = Folder.selectDialog("Select the folder:");
dir.getFiles(function(v){k0 = (key = decodeURI(v.name)
.split(/\d+/))[0], v.rename(k0 + eval('objct[k0] '
+ ({1: '', 0: '+'})[+!objct[k0]] + '= 1') + key[1])});

 

 

Perhaps Kukurykus can adapt the script to work with selected thumbs or folder in Bridge.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 16, 2022 Mar 16, 2022

Copy link to clipboard

Copied

File(app.document.presentationPath)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 16, 2022 Mar 16, 2022

Copy link to clipboard

Copied

so like  :

File(app.document.presentationPath)
dir.getFiles(function(v){k0 = (key = decodeURI(v.name) .split(/\d+/))[0], v.rename(k0 + eval('objct[k0] ' + ({1: '', 0: '+'})[+!objct[k0]] + '= 1') + key[1])});

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines