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

Batch Rename in Script

Participant ,
Jun 26, 2021 Jun 26, 2021

Is that possible to Batch Rename in Script ?

Thanks in Advance

TOPICS
Actions and scripting
3.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

correct answers 1 Correct answer

Community Expert , Jun 26, 2021 Jun 26, 2021

Write a Photoshop script javascript can rename files and has no problem getting a file list of all file in a folder. Process the file list  use some some jaming rules the generate the ned file names. You sitld matain the  file type extensing each file you remane has.  You can Process any file types you want to remane. You need to write the code you know the names you want to use.  You also need to log any failures for fileobj.rename.  Open files may be locked or you may  genetated and invalid fi

...
Translate
Adobe
Community Expert ,
Jun 26, 2021 Jun 26, 2021

File >> Automate >> Batch

Once you change to folder the bottom right will no longer be greyed out.

MikeGondek_0-1624736329766.png

 

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
Participant ,
Jun 26, 2021 Jun 26, 2021

Yes I know, But I want to Script of Batch Rename

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 ,
Jun 26, 2021 Jun 26, 2021

What do you want to rename  open documents that not possible. Layers in all in layers  image files on your system supported by Photoshop.  That could take quire some time what would happen if there was a power failure while the script was processing all the layered files on your system.  You should provide more information about the renaming you want to batch.

JJMack
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
Participant ,
Jun 26, 2021 Jun 26, 2021

I want to Rename All Images From Directory, Is that possible to Batch Rename in Scripts ?

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
Participant ,
Jun 26, 2021 Jun 26, 2021

I have a script but it's a br...

 

#target bridge
if( BridgeTalk.appName == "bridge" ) {
dangerousRenamer = new MenuElement("command", "File Renamer", "at the end of Thumbnail");
}
dangerousRenamer.onSelect = function () {
mainRenamer();
}

function mainRenamer(){
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,500,270],"+
"panel0:Panel{bounds:[10,10,390,160] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[100,5,360,39] , text:'Rename - Replace' ,properties:{scrolling:undefined,multiline:undefined}},"+
"From:EditText{bounds:[20,90,190,110] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"statictext1:StaticText{bounds:[20,65,121,85] , text:'Replace' ,properties:{scrolling:undefined,multiline:undefined}},"+
"statictext2:StaticText{bounds:[200,65,330,85] , text:'With' ,properties:{scrolling:undefined,multiline:undefined}},"+
"To:EditText{bounds:[200,90,370,110] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Global:Checkbox{bounds:[20,40,100,60] , text:'Global' },"+
"Case:Checkbox{bounds:[101,40,250,60] , text:'Case Insensitive' },"+
"button0:Button{bounds:[20,120,190,141] , text:'Ok' },"+
"button1:Button{bounds:[200,120,370,141] , text:'Cancel' }}};";

var win = new Window(dlg,"Bridge Rename Replace");
if(app.version.substr(0,app.version.indexOf('.'))>1){
win.panel0.title.graphics.font = ScriptUI.newFont("Arial","BOLDITALIC",26);
g = win.graphics;
b=win.panel0.title.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.20, 1]);
g.backgroundColor = myBrush;
var myPen =b.newPen (g.PenType.SOLID_COLOR, [0.00, 0.00, 0.99, 1],lineWidth=1);
var myPen2 =b.newPen (g.PenType.SOLID_COLOR, [0.99, 0.00, 0.00, 1],lineWidth=1);
g.foregroundColor = myPen;
b.foregroundColor = myPen2;
}
win.center();

var done = false;
while (!done) {
var x = win.show();
if (x == 0 || x == 2) {
win.canceled = true;
done = true;
} else if (x == 1) {
done = true;
var result = validate();
if(result != true) {
alert(result);
return;
}else
{
processFiles();
}
}
}

function validate(){
return true;
}
function processFiles(){
var items = app.document.selections;
try{
if(win.panel0.Global.value && !win.panel0.Case.value) var changeFrom = new RegExp (win.panel0.From.text,"g");
if(!win.panel0.Global.value && win.panel0.Case.value) var changeFrom = new RegExp (win.panel0.From.text,"i");
if(win.panel0.Global.value && win.panel0.Case.value) var changeFrom = new RegExp (win.panel0.From.text,"gi");
if(!win.panel0.Global.value && !win.panel0.Case.value) var changeFrom = new RegExp (win.panel0.From.text);
}catch(e){
alert("Incorrect Replace entered\rThis should be a Regular Expression");
return;
}
for (var a =0;a<items.length;a++){
var file = items[a];
var ext = '.' + file.name.substr(file.name.indexOf('.')+1);
var fileName = file.name.slice(0,-4).replace(changeFrom,win.panel0.To.text);
fileName += ext;
var changeFile = new File(file.path);
changeFile.rename(fileName);
}
}
}

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 ,
Jun 26, 2021 Jun 26, 2021

Write a Photoshop script javascript can rename files and has no problem getting a file list of all file in a folder. Process the file list  use some some jaming rules the generate the ned file names. You sitld matain the  file type extensing each file you remane has.  You can Process any file types you want to remane. You need to write the code you know the names you want to use.  You also need to log any failures for fileobj.rename.  Open files may be locked or you may  genetated and invalid file name.

 

rename()
fileObj.rename (newName) newName The new file name, with no path.
Renames the associated file. Does not resolve aliases, but renames the referenced alias or shortcut file itself.
Returns true on success.

 

#target photoshop;
main();
function main(){
	var selectedFolder = Folder.selectDialog("Please select  folder");
	if(selectedFolder == null) return;
	var fileList= selectedFolder.getFiles();
	if(fileList.length>0){
		var names = "";
		for (var i = 0; i < fileList.length; i++) {  
			if (i==0 )   names =  '"' + decodeURI(fileList[i].name) + '"';
			else names = names + '\n"' + decodeURI(fileList[i].name) + '"';
		}
		logInfo(names)
	}
}
	

function logInfo(Txt){
    try {	
       var file = new File(Folder.desktop + "/out.txt"); 
       file.open("w", "TEXT", "????"); 
       //alert(file.encoding);
       file.encoding = "UTF8";
       file.seek(0,2);   
       $.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';
       file.writeln(Txt); 
       if (file.error) alert(file.error);
       file.close();
       file.execute(); 
    }
    catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
};   

 

 

JJMack
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
Participant ,
Jun 26, 2021 Jun 26, 2021
LATEST

Thanks @JJMack 

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