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

Filenames are numerical code- need last four #'s to be the first four #'s

New Here ,
Mar 23, 2009 Mar 23, 2009
How do I switch the .jpg of numbers to the beginning of filenames?

I have several hundred files whose filenames have three sets of numbers separated by underscores.

Unfortunately, the last four numbers need to be placed at the beginning of the filenames. This is to establish chronology.

The current number sequence is: site number, date, number of the jpg

The desired number sequence is: jpg number, site number, date.

".jpg" would still be the last entry.

Thanks for any help!
TOPICS
Actions and scripting
1.0K
Translate
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
Adobe
Community Expert ,
Mar 24, 2009 Mar 24, 2009
This might help:


var theFolder = Folder.selectDialog("select the folder containing the images to be renamed");

if (theFolder) {

var theFiles = theFolder.getFiles();

for (var m = 0; m < theFiles.length; m++) {

var theName = theFiles.name;

var theLastNumbers = theName.slice( theName.lastIndexOf("_") + 1, -4);

var theRest = theName.slice(0, theName.lastIndexOf("_"));

theFiles.rename(theLastNumbers + "_" + theRest + ".jpg")

}

};

else {

alert ("no selection")

};

use it at Your own risk

Edit: Actually it should include some function to ascertain that the files are indeed jpgs or at least retain the original suffix.
Still if the folder contains only jpgs it should work.
Translate
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
New Here ,
Mar 24, 2009 Mar 24, 2009
Where does all this code get pasted in? First time I've done this.
Translate
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 24, 2009 Mar 24, 2009
Paste it into a new file in ExtendScript Toolkit and save it as a jsx-file. (ExtendScript Toolkit should have been automatically installed when You installed Photoshop.)
You can run it by hitting the play-button in the windows upper bar or place it in Photoshop  Presets  Scripts.
But it doesnt strictly belong to Photoshop as it does nothing within that program.
Please try it on a duplicate-folder first for testing-purposes.
Translate
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 24, 2009 Mar 24, 2009
Here's a different way to get the new file name from the old file name:

newName = oldFile.name.replace(/(\d+_\d+)(_)(\d+)\.jpg/, "$3$2$1.jpg");

-X
Translate
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 24, 2009 Mar 24, 2009
LATEST
Dang, thats cool!
(And  to me at least still pretty mysterious.)
Translate
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