UNPKG

t-comm

Version:

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

38 lines (31 loc) 1.1 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var fs = require('fs'); var path = require('path'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); var path__default = /*#__PURE__*/_interopDefaultLegacy(path); function collectFilesSync(dirPath, fileList) { if (dirPath === void 0) { dirPath = ''; } if (fileList === void 0) { fileList = []; } if (!fs__default["default"].existsSync(dirPath)) { console.log('[Not Exists]', dirPath); return []; } var items = fs__default["default"].readdirSync(dirPath); items.forEach(function (item) { var fullPath = path__default["default"].join(dirPath, item); var stat = fs__default["default"].statSync(fullPath); if (stat.isDirectory()) { collectFilesSync(fullPath, fileList); // 递归进入子目录 } else { fileList.push(fullPath); // 将文件路径加入数组 } }); return fileList; } exports.collectFilesSync = collectFilesSync;