Skip to main content
Participant
November 8, 2012
Question

Get the folder path and exclude the filename.

  • November 8, 2012
  • 1 reply
  • 556 views

Hi guys,

I am writing a ps script (in javascript) which involves the user navigating to and then selecting a file. The path of the file is then saved to a text file 'path.txt' and is called upon later in the script - for various reasons.

For example:

At the moment, when the file is navigated to and then selected, it will write to the text file:

/h/Art/Textures/MainTexture.tga

Up until now that is what i needed it to do, but now i need a slight modification.

What i need is for it to just write:

/h/Art/Textures

- Excluding the filename.

The code that i am currently using for this, is as follows:

UpdatePaths.onClick=function() {

     saveFile = File.openDialog("Select the file you are working on:", "All Formats: *.*");

     var txtPath = new File("C:\\path.txt");

     txtPath.open('w');

     txtPath.writeln(saveFile);

     txtPath.close(1);

     fileDialog.close(1);

};

Hopefully this is just an easy tweak?

Any help would be much appreciated.

Many thanks,

Adam

This topic has been closed for replies.

1 reply

Participant
November 8, 2012

Looks like i've found the solution.

Here it is for future reference:

var selectedFolder = Folder.selectDialog("Select a folder");

Paul Riggott
Inspiring
November 8, 2012

What you are looking for is...

var selectedFolder = activeDocument.path;

The user could select any folder with your solution, and may have nothing to do with the selected file.