我想從我的 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);
如果需要,它可以折疊成一個語句