const  fs = require('fs');
const  join = require('path').join;
/**
 * 
 * @param startPath  起始目录文件夹路径
 * @returns {Array}
 */
function findSync(startPath) {
    let result=[];
    function finder(path) {
        let files=fs.readdirSync(path);
        files.forEach((val,index) => {
            let fPath=join(path,val);
            let stats=fs.statSync(fPath);
            if(stats.isDirectory()) {
                result.push(fPath);
                // 递归读取文件夹下文件
                // finder(fPath)
            };
            // 读取文件名
            // if(stats.isFile()) result.push(fPath);
        });

    }
    finder(startPath);
    console.log(result)
    return result;
}
let fileNames=findSync('./');

 

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-12-30
  • 2022-03-10
  • 2022-12-23
  • 2021-05-31
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2021-11-03
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案