cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
jtandrews3
Level I

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

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 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

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

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);

it can be collapsed into one statement if desired

Jim

View solution in original post

1 REPLY 1
txnelson
Super User

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

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);

it can be collapsed into one statement if desired

Jim

Recommended Articles