cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
yvesprairie
Level IV

extracting the directory of a jmp file in JSL

Hi all,

 

I have managed to do what I want in a convoluted way (using word and character manipulations)  but I feel there must be an easier way to do this. All I want is to extract the directory of a file I just selected using the Pick File function in JSL so that the next time, it starts from that directory. Any suggestions??

 

Thanks, Yves

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: extracting the directory of a jmp file in JSL

Take a look at my script below, and tell me if I am getting closer to what you want.

Names Default To Here( 1 );
theDirectory = "";
xx = Pick File( "Pick a File", theDirectory );
theDirectory = Substr( xx, 1, Length( xx ) - Length( Word( -1, xx, "\/" ) ) - 1 );


// now this Pick File will go to the directory that the file from the last
// Pick File was selected from
yy = Pick File( "Pick a File", theDirectory );

// If you want this Pick File to span across different scripts, then it would be a simple
// matter to save the directory in a specific namespace and get the 
// directory location from a variable saved in that namespace.

// If you want to have the Pick File directory available from JMP session to JMP session
// then what I have used in the past, is to simply save the character string for the 
// directory to a .txt file, using Save Text File() and Load Text File() to make the directory 
// persistant
Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: extracting the directory of a jmp file in JSL

Check out the Files in Directory() function in the Scripting Index

txnelson_0-1633216297555.png

 

 

Jim
yvesprairie
Level IV

Re: extracting the directory of a jmp file in JSL

Sorry I pressed the wrong button!!! Unfortunately, this is not a solution @txnelson . This only lists the files of a known directory. I want to browse to find the file I want and once I have chosen it, I want to save the directory so that next time I want to browse , it starts at that previous directory.

 

Cheers, Yves

txnelson
Super User

Re: extracting the directory of a jmp file in JSL

Take a look at my script below, and tell me if I am getting closer to what you want.

Names Default To Here( 1 );
theDirectory = "";
xx = Pick File( "Pick a File", theDirectory );
theDirectory = Substr( xx, 1, Length( xx ) - Length( Word( -1, xx, "\/" ) ) - 1 );


// now this Pick File will go to the directory that the file from the last
// Pick File was selected from
yy = Pick File( "Pick a File", theDirectory );

// If you want this Pick File to span across different scripts, then it would be a simple
// matter to save the directory in a specific namespace and get the 
// directory location from a variable saved in that namespace.

// If you want to have the Pick File directory available from JMP session to JMP session
// then what I have used in the past, is to simply save the character string for the 
// directory to a .txt file, using Save Text File() and Load Text File() to make the directory 
// persistant
Jim
yvesprairie
Level IV

Re: extracting the directory of a jmp file in JSL

Yes this works great! It is close (but better) than what I had come up with. I just thought there should be a built-in function to extract the location (the directory path) of a file. Many thanks @txnelson !

 

Regards, Yves