Skip to main content
Participating Frequently
August 13, 2025
Answered

Use importTextData / Want to open to a file directory only / Then user picks file

  • August 13, 2025
  • 2 replies
  • 304 views

I have a trusted function to import a text file from a button.   It works fine when I specify the file path including a specific text file.  I am wanting to open to the file directory and let the user select from the .txt files in that folder.  If I don't include an actual file.txt name, nothing happens, the path to the directory with the text files does not open.  The code I'm trying to use with the button is:

 

var thepath = getCurrentDirectory;

myImportTextData(thepath);

 

My trusted function code is:

 

myImportTextData = app.trustedFunction(function(cPath)
{
app.beginPriv();
this.importTextData(cPath);
app.endPriv();
});

 

Correct answer try67

You can't specify the default folder to open the dialog to, if that's what you mean.

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 13, 2025

You can't specify the default folder to open the dialog to, if that's what you mean.

wes@ESAAuthor
Participating Frequently
August 14, 2025

Thank you for your reply.  Yes that's what I'm trying to do.  Using importTextData() without a specific path to a file opens up the wrong directory.  User has to navigate on their own to find what I'm trying to import.  

Nesa Nurani
Community Expert
Community Expert
August 13, 2025

Try this:

button script:

myImportTextData();


Trusted function:

myImportTextData = app.trustedFunction(function() {
app.beginPriv();
this.importTextData(); 
app.endPriv();
});

wes@ESAAuthor
Participating Frequently
August 14, 2025

Thank you for your reply.   When I don't specify a path to a specific file the dialogue box opens up showing the wrong directory.  User has to navigate on their own to find what I'm trying to import.  The directory I wanted to point to has three different text files that the user can select.

 

Nesa Nurani
Community Expert
Community Expert
August 14, 2025

It will open the last folder that you imported the file from, so if you wish it to be a specific folder just import the file from it and next time it will open that folder by default.