Follow

How can I prompt a user for a file path in a Surfer script?

Q: The GetFilePath function prompts the user for a specific file. I am trying to find a way to open a dialog asking for a specific directory.

 

A: The easiest way is to use an InputBox, where you would enter the entire path manually.

'Open a dialog asking user to enter file path
FilePath$=InputBox$("Enter file path. For example, C:\Users\<your username>\Desktop\", "File Path", "")

'If the file path is left empty, stop the script
If FilePath$ ="" Then End

'If the file path is missing the \ at the end, add it
If Len(FilePath$)-InStrRev(FilePath$,"\") <> 0 Then FilePath$ = FilePath$ + "\"

 

Alternatively, if there are any files in the directory, you can use the CurDir function to select a file and then just save the path to that file.

'Open a dialog asking user to select a DAT, TXT, CSV, or XLS file
filename = GetFilePath(" ","DAT;TXT;CSV;XLS",CurDir(), "Select file in desired directory", 0)

'Set the file path to the directory of the chosen file
FilePath$ = CurDir(filename)

'If the file path is left empty, stop the script
If FilePath$ ="" Then End

'If the file path is missing the \ at the end, add it
If Len(FilePath$)-InStrRev(FilePath$,"\") <> 0 Then FilePath$ = FilePath$ + "\"

 

If you decide to use the latter option, you would just change the "DAT;TXT;CSV;XLS" in that first line to the file extension of the file in the desired directory.

 

Both of these options are BASIC Automation options, which are not specific to Surfer. You can click Help | BASIC Language Help from within Scripter to find various help topics about these BASIC Automation options.

 

Updated November 9, 2018

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.