Subscribe Bookmark RSS Feed

Strip path: how to get a directory from a file path variable in JMP script

jtandrews3

Community Member

Joined:

Dec 7, 2016

I would like to get the directory from a file path variable in my JMP script.

I'm opening a data file and want to save the analysis results in the same folder that the file is in. 

I've found a clunky solution, but was hoping there was a more elegant solution for this. 

Here's my current code: 

 

// Choose the directory that has the test data. 
EMfile = Pick File("Select the file containing the EM summary table.");
// The next code is a clumsy way to get the directory of EMfile, but it works. 
a = 1;
b = 1;
while (a != 0,
  b = a+1;
  a = munger(EMfile, b, "/");
);
b--;
file_dir = munger(EMfile, 0, b);

 

1 REPLY
txnelson

Super User

Joined:

Jun 22, 2012

here is a fairly clean pice of code that does what you want

filelength = length(word(-1,emfile,"\/"));
pathlength=length(emfile)-filelength-1;
path=substr(emfile,1,pathlength);

i can be collapsed into one statement if desired

Jim