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

Remove file path keep folder name

Engaged ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

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

Views

246

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

Community Expert , 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
...

Votes

Translate

Translate
Community Expert ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

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);

 

Votes

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

Copy link to clipboard

Copied

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

 

Votes

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

Copy link to clipboard

Copied

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.

Votes

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