如何循环遍历多个 csv 文件并根据特定文件名选择它们?这是我的代码:
path = "/users/BOT/Test_files/";
Set File Search Path( mypath );
// filter out all csv files in the path that contains "Pass" && Not contains "Conditional_Pass" or "Fail" in file name
y = Files In Directory( mypath );
For( i = N Items( y ), i > 0, i--,
If( (Ends With( y[i], ".csv" ) & Contains( y[i], "Pass" ) & Not( Contains( y[i], "Conditional_Pass" ) ) & Not( Contains( y[i], "Fail" ) )),
,
Remove From( y, i )
)
);
n = N Items( y );
继续出现如下屏幕截图所示的错误,是因为Files In Directory()函数已被弃用吗?
有趣的是,上述代码曾经适用于 JMP16,但昨天我升级到 JMP17 后出现以下错误。

数据访问回复:如何循环遍历多个 csv 文件并根据特定文件名选择它们?您最有可能遇到该错误,因为您正在删除循环的同一列表。对于这种类型的过滤,我建议使用 Filter Each 而不是 For 循环。
另外,您是否尝试过使用多文件导入?
回复:如何循环遍历多个 csv 文件并根据特定文件名选择它们?请检查路径与mypath
除此之外,您还可以使用Filter Each而不是for循环:
//path = "/users/BOT/Test_files/";
mypath = "/users/BOT/Test_files/";
y = Files In Directory( mypath );
y = filter each({fn}, y, Ends With( fn, ".csv" ) & Contains( fn, "Pass" ) & Not( Contains( fn, "Conditional_Pass" ) ) & Not( Contains( fn, "Fail" ) ) )回复:如何循环遍历多个 csv 文件并根据特定文件名选择它们?您也可以采取下一步并升级到 JMP18 - 并可以选择在 MultiFileImport 中使用文件列表。
在某些情况下,这将使数据导入速度提高几个数量级!
y= Transform each ({fn}, y, mypath || fn);
Eval(Eval Expr (Multiple File Import(
<<SET use="" file="" list=""></SET><BR />At the moment, Filelist + <FONT face="courier new,courier">多文件导入</FONT> needs the complicate <FONT face="courier new,courier">Eval(Eval Expr(... Expr(...))</FONT>.<BR />This will get fixed in a future release of JMP.
回复:如何循环遍历多个 csv 文件并根据特定文件名选择它们?我认为您打开了一个数据表,其中有一列名为 Y。JSL 正在尝试使用该表的列,但这并不是您想要的。要么关闭该表,要么在表或脚本中更改名称,要么使用范围来告诉 JMP 您指的是哪个。
此示例在 Y 进入任何命名空间之前启动 JMP。

@Audrey_Shull - 如果该错误对话框能命名变量所来自的表,那么它的效果会好 100%。
回复:如何循环遍历多个 csv 文件并根据特定文件名选择它们?谢谢 Craige,是的,我一天前发现了我的错误并解决了它,就像你的描述一样。
回复:如何循环遍历多个 csv 文件并根据特定文件名选择它们?谢谢hog,过滤各个功能也给了我一些启发。
回复:如何循环遍历多个 csv 文件并根据特定文件名选择它们?嘿 jthi,谢谢你。
同意多文件导入是一种解析文件的好方法,比我当前的方法更快。