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

Remove file path keep folder name

Engaged ,
Dec 15, 2022 Dec 15, 2022

The Bridge alert dialog displays the folder name KGD with the file path.

How can I remove the file path and keep the KGD folder name?

      button1.onClick = function() {
        var folderName = Folder.selectDialog("");
        alert('alert 1: '+folderName);
      }

Screen Shot 2022-12-15 at 7.55.57 PM.png 

TOPICS
Scripting
402
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

Advocate , Dec 15, 2022 Dec 15, 2022

You can find the index of the last "/" in folderName then get the substring after that

var folderName = Folder.selectDialog("");
var lastFolderIndex = folderName.toString().lastIndexOf("/");
var lastFolder = folderName.toString().substr(lastFolderIndex+1);  
alert('alert 1: '+lastFolder);

 

You can split folderName into an array based on "/" then get the last array item

var folderName = Folder.selectDialog("");
var folderNameToArray = folderName.toString().split("/");
var lastFolder = folderName
...
Translate
Advocate ,
Dec 15, 2022 Dec 15, 2022

You can find the index of the last "/" in folderName then get the substring after that

var folderName = Folder.selectDialog("");
var lastFolderIndex = folderName.toString().lastIndexOf("/");
var lastFolder = folderName.toString().substr(lastFolderIndex+1);  
alert('alert 1: '+lastFolder);

 

You can split folderName into an array based on "/" then get the last array item

var folderName = Folder.selectDialog("");
var folderNameToArray = folderName.toString().split("/");
var lastFolder = folderNameToArray[folderNameToArray.length-1];
alert('alert 1: '+lastFolder);

 

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
Advocate ,
Dec 15, 2022 Dec 15, 2022

This might be the simplest method (only tested on Windows)

 

var folderName = Folder.selectDialog("");
alert('alert 1: '+folderName.name);
alert('alert 2: 'folderName.displayName); // displays spaces instead of %20

 

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
Engaged ,
Dec 16, 2022 Dec 16, 2022
LATEST

Many thanks for the explanation. The first two code samples work great.

The third code is simple and elegant but throws an error in the mac system.

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