我在node.js中运行这段代码,以便查看目录中的文件以查看它们的统计信息:
var getFiles = function (dir, done) {
fs.readdir(dir, function (err, files) {
if (err) return done(err);
var pending = files.length;
files.forEach(function (file) {
fullPath = dir + "/" + file;
console.log(fullPath);
fs.stat(fullPath, function (err, stat) {
if (err) {
console.log("Stat error");
} else if (stat && stat != undefined) {
console.log("Success");
}
});
});
});
}
我的问题是包含特殊字符的文件名。我是瑞典人,所以有很多å,ä和ö。当输出大多数文件名时,fullPath的输出是正确的,但每当文件名包含特殊字符时,该字符显示为“?”,然后fs.stat失败,因为它无法找到该文件。我错过了什么?我正在Windows上运行v0.5.7版本 提前谢谢。