我无法从此处获取串行示例,但无法提供链接(?):
NodeJS:如何在服务器端查看大量文件/文件夹以进行更新?
var fs = require('fs');
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var i = 0;
(function next() {
var file = list[i++];
if (!file) return done(null, results);
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
next();
});
} else {
results.push(file);
next();
}
});
})();
});
};
我试过这个来调用函数,但我不确定它需要什么参数。有人可以建议吗?
//walk(process.env.HOME, function(err, results) {
walk("C:\", function(err, results) {
if (err) throw err;
console.log(results);
});
我得到的错误是
module.js:437
var compiledWrapper = runInThisContext(wrapper, filename, true);
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)