vuepress-plugin-helper-live2d
Version:
VuePress集成Live2D看板娘. Live2D plugin for VuePress.
32 lines (30 loc) • 867 B
JavaScript
/**
* @description List files of provided path
*/
const fs = require('fs');
const path = require('path');
/**
* Lists files in the supplied directory path
* @param {String} dirPath The path to the dir
* @return {Array} An array that contains all the file paths
*/
module.exports = function listFiles(dirPath) {
try {
// 指定目录下所有文件名称
const lsDir = fs.readdirSync(dirPath);
const filesArr = [];
for (const fileName of lsDir) {
const pathName = path.join(dirPath, fileName);
if (fs.statSync(pathName).isDirectory()) {
// 三点运算符
filesArr.push(...listFiles(pathName));
} else {
filesArr.push(pathName);
}
}
return filesArr;
} catch (e) {
console.warn("Not Found dirPath Files:" + dirPath);
return null;
}
};