MAXScript 官方文档里关于获取文件夹下所有文件的方法
fn getFilesRecursive root pattern = ( dir_array = GetDirectories (root+"/*") for d in dir_array do join dir_array (GetDirectories (d+"/*")) my_files = #() for f in dir_array do join my_files (getFiles (f + pattern)) my_files ) --get all .ms files from the folder c:/temp --and all its subfolders: getFilesRecursive "c:/temp" "*.ms"
测试后发现无法获取单个文件夹内的文件,比如"C:/temp"下只有文件"1.ms","2.ms"就无法获取.
解决办如下
fn getFilesRecursive root pattern = ( dir_array = GetDirectories (root+"/*") for d in dir_array do join dir_array (GetDirectories (d+"/*")) my_files = #() if dir_array.count == 0 do append dir_array (root + "\\") for f in dir_array do join my_files (getFiles (f + pattern)) my_files )
这样就可以了,如果搜索目录内没有其他文件夹,那么就搜索该目录内的文件.
时间: 2024-11-10 22:29:54