获取文件夹和子文件夹中的所有文件

javascript
阅读 46 收藏 0 点赞 0 评论 0

walksync.js

function walkSync(currentDirPath, callback) {
  // attrib: https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j

  fs.readdirSync(currentDirPath).forEach(function (name) {
    var filePath = path.join(currentDirPath, name);
    var stat = fs.statSync(filePath);
    if (stat.isDirectory()) {
      if (hasChildDirectories(filePath)) {
        walkSync(filePath, callback);
      }
      callback(filePath, stat);
    }
  });
}
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号