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

Problem renaming a file with a © symbol

New Here ,
May 17, 2022 May 17, 2022

The version of Bridge that I'm using has a bug that reverses the order of the images when I import them.  I'm trying to write a extendscript to reverse the order of the images by renaming them.  For example if I import five images, image one needs to be renamed image five and image two needs to be renamed image four etc.  The problen seems to be my standard filenaming format:  ©_Stan_Tess_20220516_0005.ARW.  If I remove the © symbol I can rename the file but not with the symbol.  If I use Batch Rename... within Bridge I can add the © symbol but I would like to do it in the script.  Thanks!

 

#target bridge
if(BridgeTalk.appName == 'bridge'){
try{


//create menu

var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');

var ftcpPath = MenuElement.create('command', 'Image Order Fix', 'after Thumbnail/Open', this.menuID); //add to Contextual menu


cpPath.onSelect = function(){
ImageOrderFix();
}

ftcpPath.onSelect = function(){
ImageOrderFix();
}

function ImageOrderFix(){

var thumbs = app.document.selections;
var selectedFile = new Thumbnail(thumbs[0]);

MyFolder = decodeURI(selectedFile.spec.parent.toString());

var folder = Folder(MyFolder);


var files = folder.getFiles();
var file, extension, baseName, rename;

for(var i = 1; i < files.length; i++){
file= files[i];
extension = files[i].name.slice(files[i].name.length-4, files[i].length);
baseName =files[i].name.slice(6, files[i].name.length-8);
rename= ((files.length) -i ).toString();

switch(rename.length.toString() ) {
case "1":
rename= "000" + rename
break;
case "2":
rename= "00" + rename
break;
case "3":
rename= "0" + rename
break;
case "4":
//~ rename = rename
break;

}

rename = baseName +rename +extension

//~ file.rename(rename);
file.rename( "©" + rename);
//~ file.rename( String.fromCharCode(169) +rename);
}


}
}
catch(e){
alert(e + ' ' + e.line);
}
}

TOPICS
Scripting
535
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 , May 17, 2022 May 17, 2022

There's definitely something weird with "©_" on Windows.


This is a workaround so I'm not confident recommending it, but I was able to rename using "©X_"  and then rename again removing the "X". 

Also, I had to change your loop to begin at 0 to get all the files to rename:

for(var i = 0; i < files.length; i++){ 

 

#target bridge
if(BridgeTalk.appName == 'bridge'){
try{


//create menu

var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');

var ftcpPath = MenuElement.cre
...
Translate
Community Expert ,
May 17, 2022 May 17, 2022

I haven't had time to test, however, I'd suggest that you try to use the code instead:

 

\xA9

 

https://charbase.com/00a9-unicode-copyright-sign

 

 

 

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 ,
May 17, 2022 May 17, 2022

Hi, Thanks, I missed that one in my search but unfortunately "\xa9" doesn't work either.  I had previously tried String.fromCharCode(169)  and  "\©" before but they also didn't 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
Community Expert ,
May 17, 2022 May 17, 2022

Are you using Windows?

 

I'm on a Mac and the © symbol worked for me in Bridge 2022.

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 ,
May 17, 2022 May 17, 2022

Yes I'm on Win 11 and Bridge 2022 but I also have Bridge CS6.  CS6 doesn't like the code either.

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 ,
May 17, 2022 May 17, 2022

I just tested it on Win 10 & Bridge CS6 and that too is a no go.

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 ,
May 17, 2022 May 17, 2022

I'm on Windows 10 as well.

I canot figure this out. Wierdly, if I add a character afert the ©, it works, i.e. file.rename( "©_"+rename)

I've tried removing the leading underscore from baseName and then using file.rename( "©_"+rename), but that doesn't 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 ,
May 17, 2022 May 17, 2022

That is bizarre.  I just tried removing "_Stan_" from baseName and then using file.rename( "©_Stan_"+rename), but that doesn't work either. I also tried adding  a second _ to file.rename( "©__Stan_"+rename) and that works but it's not in my naming convention.  Then I tried file.rename( "b©_Stan_" + rename) and that works as well and so does file.rename( "©Stan_" + rename).   I then added "Stan_" back to baseName and then used file.rename( "©\_" + rename) Which works but screwed up my i incrementor.  I'll see if I can figure that out in the morning.  It seems the problem is the "©_"  combination and a way to escape it.

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 ,
May 17, 2022 May 17, 2022

There's definitely something weird with "©_" on Windows.


This is a workaround so I'm not confident recommending it, but I was able to rename using "©X_"  and then rename again removing the "X". 

Also, I had to change your loop to begin at 0 to get all the files to rename:

for(var i = 0; i < files.length; i++){ 

 

#target bridge
if(BridgeTalk.appName == 'bridge'){
try{


//create menu

var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');

var ftcpPath = MenuElement.create('command', 'Image Order Fix', 'after Thumbnail/Open', this.menuID); //add to Contextual menu


cpPath.onSelect = function(){
ImageOrderFix();
}

ftcpPath.onSelect = function(){
ImageOrderFix();
}

function ImageOrderFix(){

var thumbs = app.document.selections;
var selectedFile = new Thumbnail(thumbs[0]);

MyFolder = decodeURI(selectedFile.spec.parent.toString());

var folder = Folder(MyFolder);

var files = folder.getFiles();
var file, extension, baseName, rename;

for(var i = 0; i < files.length; i++){
file= files[i];
// ©_Stan_Tess_20220516_0005
// %C2%A9_Stan_Tess_20220516_0005.jpg

extension = files[i].name.slice(files[i].name.length-4, files[i].length);
baseName =files[i].name.slice(6, files[i].name.length-8);
rename= ((files.length) -i ).toString();

switch(rename.length.toString() ) {
case "1":
rename= "000" + rename
break;
case "2":
rename= "00" + rename
break;
case "3":
rename= "0" + rename
break;
case "4":
//~ rename = rename
break;
}

rename = baseName +rename +extension
//~ file.rename(rename);
file.rename( "©X"+rename);
//~ file.rename( String.fromCharCode(169) +rename);
}

for(var ii = 0; ii < files.length; ii++){
    file= files[ii];
    rename2 = files[ii].name.split("X_").join("_")
    file.rename(rename2);
    }

}
}
catch(e){
alert(e + ' ' + e.line);
}
}

 

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 ,
May 18, 2022 May 18, 2022
LATEST

Thanks, your solution works.  I came up with a very simular approach except I don't add anything extra and remove it later.  For some reason how I do the rename screwed with the i incrementor.  That's why I changed to start with 1 but now I too had to change back to 0.  

 

#target bridge
if(BridgeTalk.appName == 'bridge'){
try{


//create menu

var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');

var ftcpPath = MenuElement.create('command', 'Image Order Fix', 'after Thumbnail/Open', this.menuID); //add to Contextual menu


cpPath.onSelect = function(){
ImageOrderFix();
}

ftcpPath.onSelect = function(){
ImageOrderFix();
}

function ImageOrderFix(){

var thumbs = app.document.selections;
var selectedFile = new Thumbnail(thumbs[0]);
var folder = Folder(decodeURI(selectedFile.spec.parent.toString()));
var files = folder.getFiles();
var file, extension, baseName, rename;

for(var i = 0; i < files.length; i++){
file= files[i];
extension = files[i].name.slice(files[i].name.length-4, files[i].length);
baseName =files[i].name.slice(7, files[i].name.length-8);
rename= ((files.length) -i ).toString();

switch(rename.length.toString() ) {
case "1":
rename= "000" + rename
break;
case "2":
rename= "00" + rename
break;
case "3":
rename= "0" + rename
break;
case "4":
break;

}

rename = baseName +rename +extension
file.rename(rename);

}
for(var i = 0; i < files.length; i++){
file= files[i];
rename2= files[i].name.toString();
file.rename( "©\_" + rename2);
}

}
}

catch(e){
alert(e + ' ' + e.line);
}

}

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