我想从我的 JMP 脚本中的文件路径变量中获取目录。
我正在打开一个数据文件并想将分析结果保存在该文件所在的同一文件夹中。
我找到了一个笨拙的解决方案,但希望有一个更优雅的解决方案。
这是我当前的代码:
// 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);
这是一段相当干净的代码,可以满足您的需求
filelength = length(word(-1,emfile,"\/"));
pathlength=length(emfile)-filelength-1;
path=substr(emfile,1,pathlength);
如果需要,它可以折叠成一个语句