cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
BabyDoragon
Level I

How to Record User-Selected Folder Paths for Subsequent Data Access

How can I implement saving the user-defined folder path so that the script can directly read data from this default folder path during the next run?
I want to read data from a folder, but I cannot predict where the user will set this folder. Therefore, during the first run, I need to be able to record the user-defined folder path. I know that using 'pick file' allows the user to select data, but I don't know how to store this record so that it can be directly read from that folder when this script is run again in the future.

5 REPLIES 5
txnelson
Super User

Re: How to Record User-Selected Folder Paths for Subsequent Data Access

Look at the Get Path() function.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
path = dt << Get Path();
Show( path );
Jim
BabyDoragon
Level I

Re: How to Record User-Selected Folder Paths for Subsequent Data Access

I need to be able to record this path, so that the user doesn't have to pick the data table each time.
Simply getting the path only retrieves it at that moment, but it cannot automatically read the recorded path during the next execution of the script.

txnelson
Super User

Re: How to Record User-Selected Folder Paths for Subsequent Data Access

The easiest way to do this is to save the path to a text file at a given location on the computer.  Use 

     Save Text File()

If you add in your script something like

path = try(load text file(":c/users/jim/myfile.txt"),"");

If a previous execution of the script has saved a path to the text file location, the Path variable will be populated.

Jim
BabyDoragon
Level I

Re: How to Record User-Selected Folder Paths for Subsequent Data Access

Your meaning likely refers to saving the path that the user wants to ":c/users/jim/myfile.txt." But the same issue arises: how can I confirm that the user currently has this txt file at that path? If the location of this file is still unknown, the user will need to specify the path for myfile.txt. How can I read the location of myfile.txt the next time it is opened?

txnelson
Super User

Re: How to Record User-Selected Folder Paths for Subsequent Data Access

You can use one of the JMP Path Variables to point to a location to store and retrieve data.  From you description of what you want to do, it sounds like the functionality you want is not a critical function so placing the file into a folder in the TEMP path might be a way to handle this.  If at the beginning of your script, you have something like

Names Default To Here( 1 );

If( Is Directory( "$TEMP" || "/myfolder" ) == 0,
	rc = Create Directory( "$TEMP" || "/myFolder" )
);
If( Is File( "$TEMP" || "/myFolder/myfile.txt" ) == 1,
	thePath = Load Text File( "$TEMP" || "/myFolder/myfile.txt" )
);

You will be able to create a place to store myfile.txt if it does not exist, and if the file was placed there in a previous run, then it can be retrieved for use in the current running of the script.

 

You may want to explore other Path Variables rather than TEMP to see what location is best for your needs.

Look in 

     Help=>JMP Online Help

for documentation on the Path Variables

and in

     Help=>Scripting Index

for examples of IsDirectory() and IsFile()

 

Jim