UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

29 lines (26 loc) 737 B
import fs__default from 'fs'; import path__default from 'path'; function collectFilesSync(dirPath, fileList) { if (dirPath === void 0) { dirPath = ''; } if (fileList === void 0) { fileList = []; } if (!fs__default.existsSync(dirPath)) { console.log('[Not Exists]', dirPath); return []; } var items = fs__default.readdirSync(dirPath); items.forEach(function (item) { var fullPath = path__default.join(dirPath, item); var stat = fs__default.statSync(fullPath); if (stat.isDirectory()) { collectFilesSync(fullPath, fileList); // 递归进入子目录 } else { fileList.push(fullPath); // 将文件路径加入数组 } }); return fileList; } export { collectFilesSync };