aardio | 获取指定文件夹的所有文件列表,可以递归子文件夹

import fsys;
import console


//获取路径列表,采取true递归模式
function getAllFiles(dirPath, pattern = "*.*", recursive = true) {
    var fileList = {};
    
    fsys.enum(dirPath, pattern, 
        function(dirname, filename, fullpath, findData) {
            if (filename) {
                fileList[#fileList +1]=fullpath;
            }
            return true; // 继续枚举
        }, 
        recursive // 是否递归子目录
    );
    
    return fileList;
}

// 使用示例:
var files = getAllFiles(fsys.getCurDir());//指定文件夹是当前目录
console.log("找到的文件列表对象:", files);
for(i=1;#files;1){
    console.log("找到的文件列表完整路径:", files[i]);

}
console.pause()

 

返回的是具体的文件路径。

posted @ 2025-04-06 20:12  issacnew  阅读(128)  评论(0)    收藏  举报