搜索文件夾。我有一個代碼可以接受文件夾名稱作為輸入。現在我想檢查該文件夾是否存在於 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!"
);