小编Kar*_*bit的帖子

Nodejs path.resolve 未定义

// codenotworking

const path = require("path");
const fs = require("fs");
log = console.log;
const names = [];

function collectFileNamesRecursively(path) {
  fs.readdir(path, (err, files) => {
    err ? log(err) : log(files);

    // replacing paths
    for (const index in files) {
      const file = files[index];
      files[index] = path.resolve(path, file);
    }
    for (let file of files) {
      fs.stat(file, (err, stat) => {
        err ? log(err) : null;
        if (stat.isDirectory()) {
          collectFileNamesRecursively(file);
        }
        names.push(file);
      });
    }
  });
}
collectFileNamesRecursively(path.join(__dirname, "../public"));
Run Code Online (Sandbox Code Playgroud)

我正在使用 nodejs v10.8.0 并且目录结构是 …

javascript node.js

2
推荐指数
1
解决办法
2220
查看次数

标签 统计

javascript ×1

node.js ×1