Rename a folder with a new name [Scripting]

Community Beginner ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Hi, I'm a bit stuck with a script, I'm completely new to scripting.

 

I need photoshop to 

 

Locate a folder

Ask me for a new folder name

rename the folder

Locate another folder

Rename that folder with the same folder name

 

The folder it needs to locate will ALWAYS be the same.

 

I know this seems very simple, but I'm a complete newbie.

 

I can't find anything in the community that tells me how to get the script to ask me for the folder name I'd like to rename to.

 

Thanks,

 

Darren

TOPICS
Actions and scripting , Windows

Views

110

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

Adobe Community Professional , Jun 10, 2022 Jun 10, 2022

Perhaps try absolute URI format:

 

'/c/users/daz10/Desktop/Temp/OldFolderName'

 

Or relative:

 

'~/Desktop/Temp/OldFolderName'

 

Likes

Translate

Translate
Advocate ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

hello @Darren5EBE,

 

Give this a try as a stating point....you should put in checks to making sure the two folders are not in the same location.

      var myFolder = Folder.selectDialog ("Select folder to rename");
      if (myFolder != null){ 
      }else{
      exit();
       }

       var myNewFolderName = prompt("Enter new folder name","");
       if(myNewFolderName == null)
       { 
       exit();
       }
       if(myNewFolderName == "")
        { 
       alert ("Error!\nNo new folder name entered.");
       exit();
       }

       myFolder.rename(myNewFolderName);

       var myNextFolder = Folder.selectDialog ("Select the next folder to rename");
       if (myNextFolder != null){ 
       }else{
       exit();
       }

        myNextFolder.rename(myNewFolderName);
       
      

Regards,

Mike

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 Beginner ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Hi Mike,

 

Your script worked perfectly, my requirement is a little different, I tried to tweak your code but just can't get it to work, The folder I'm trying to rename will always be the same path, it's part of a longer script that I'm trying to cobble together.

 

Can you advise why it won't rename the folder? Your help is much appreciated. Thankyou.

 

var myFolder = Folder('C:\Users\daz10\Desktop\Temp\OldFolderName');
      if (myFolder != null){
      }else{
      exit();
       }

       var myNewFolderName = prompt("Enter new folder name","");
       if(myNewFolderName == null)
       {
       exit();
       }
       if(myNewFolderName == "")
        {
       alert ("Error!\nNo new folder name entered.");
       exit();
       }

       myFolder.rename(myNewFolderName);

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
Adobe Community Professional ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

@Darren5EBE 

 

The code you posted works for me on a Mac... The only change I made was to a cross platform relative path for the folder:

 

var myFolder = Folder('~/Desktop/test');

 

 

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
Advocate ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Hello @Darren5EBE,

Sorry I'm a Mac user.....See if this works for you...

 

var myFolder = Folder('D:/Users/daz10/Desktop/Temp/OldFolderName');
      if (myFolder != null){
      }else{
      exit();
       }

       var myNewFolderName = prompt("Enter new folder name","");
       if(myNewFolderName == null)
       {
       exit();
       }
       if(myNewFolderName == "")
        {
       alert ("Error!\nNo new folder name entered.");
       exit();
       }

       myFolder.rename(myNewFolderName);

 

Regards,

Mike

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
Adobe Community Professional ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Perhaps try absolute URI format:

 

'/c/users/daz10/Desktop/Temp/OldFolderName'

 

Or relative:

 

'~/Desktop/Temp/OldFolderName'

 

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 Beginner ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

LATEST

Worked perfectly, thkyou

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