Prompt a user for a file path in Surfer automation

The GetFilePath function prompts the user for a specific file but what if you want to prompt a user for a file path instead?

 

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 December 2021

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.