BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
Highlighted
Jaz
Jaz
Frequent Contributor

RE: Extracting the File Path of a .csv File From the File Name

Hi,

 

I've been trying to extract the file path of a csv file in order to open it. I've been using the following script:

dt = Open("File.csv");

path = Arg(dt << get property("Source"), 1);

print("path: " || path);

This prints a file not found error to the log. The file path returned shows the following:

C:\Users\jaz\Desktop\File.csv was not found.

My file is stored in a folder in the Desktop but the path does not go to the folder. In another one of my scripts the path variable I create just provides the name of the file with a backslash. I'm confused as to why one script is providing me with a path (be it the wrong one), and another is providing the file name?

Any clarification and ideas on how I could extract the full file path of the file by simply providing the name of the file would be appreciated.

  

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions

RE: Extracting the File Path of a .csv File From the File Name

Think about it: you have only a file name. How would you find its location (path)?

 

Can't you ask the user who is running the script to pick the directory with the file before the script opens it?

 

As Craige pointed out, there is a default directory in JMP and you can ask about it. You can also ask about where JMP will look with Get File Search Path(). It returns a list of paths that JMP will use to find files.

Learn it once, use it forever!
3 REPLIES 3

RE: Extracting the File Path of a .csv File From the File Name

The open statement is using the default directory. You can use the GetDefaultDirectory() and SetDefaultDirectory() functions to find out what path was used to try to open the file and set a path that you want JMP to use.

\File.csv is suggesting the default directory is \, the root of the file system.

Using the source script is a very round-about way to get the information that GetDefaultDirectory provides directly.

 

Craige

RE: Extracting the File Path of a .csv File From the File Name

Think about it: you have only a file name. How would you find its location (path)?

 

Can't you ask the user who is running the script to pick the directory with the file before the script opens it?

 

As Craige pointed out, there is a default directory in JMP and you can ask about it. You can also ask about where JMP will look with Get File Search Path(). It returns a list of paths that JMP will use to find files.

Learn it once, use it forever!
Jaz
Jaz
Frequent Contributor

RE: Extracting the File Path of a .csv File From the File Name

I have a script in which the user basically selects the directory and then the csv file that they want to use. I realise now that I could just get the directory that the user selected and join that with the file name to open the file.

0 Kudos