搜索文件夹。我有一个代码可以接受文件夹名称作为输入。现在我想检查该文件夹是否存在于 2 个路径之一(pathA 和 PathB)中。
我也能够做到这一点,但挑战是,
我在这两个路径中有很多文件夹,我事先不知道这些文件夹的名称。
我尝试使用
filelist=Files In Directory( path1, recursive);
但这不适用于文件夹。
回复:搜索文件夹。需要稍微调整,但谢谢你! 得到了我需要的东西
回复:搜索文件夹。当然,大概就像这个未经测试的 JSL...
If( Is Directory( path || candidates[i] ),
Write( "\!n", path || candidates[i] ); // <<<<<< do something with a dir
descend( path || candidates[i] ); // optionally, recurse
, // else
Write( "\!n", path || candidates[i] ); // <<<<<< do something with a file
)
您可能需要使用 isFile(...) 来确保项目实际上是文件,而不是操作系统可能向您显示的其他奇怪的东西。
回复:搜索文件夹。可以修改代码以包含文件名和文件夹吗?
谢谢
回复:搜索文件夹。descend = Function( {path},
{candidates, i},
If( !Ends With( path, "/" ) & !Ends With( path, "\" ),
path = path || "/"
);
candidates = Files In Directory( path ); // not recursive
For( i = 1, i <= N Items( candidates ), i += 1,
If( Is Directory( path || candidates[i] ),
Write( "\!n", path || candidates[i] ); // <<<<<< do something
descend( path || candidates[i] ); // optionally, recurse
)
);
);
descend( "c:\program files" );如果您不想探索子目录,请注释掉递归行。
回复:搜索文件夹。您的代码示例使用了错误的语法。 以下是正确语法的示例:
Files In Directory( "$SAMPLE_DATA", Recursive( 1 ) );
返回的列表中的项目是完整路径,因此您可以检查每个项目以找到目标文件夹。
回复:搜索文件夹。这会对你有帮助吗?
If( Directory Exists( "$SAMPLE_DATA/Loss Function Templates" ),
"ok",
"missing!"
);