【发布时间】:2017-07-21 21:29:30
【问题描述】:
尝试使用以下答案中的代码: https://stackoverflow.com/a/24594123/3951987
为我的目录中的文件返回 true。
为了提供更多上下文,这里有一些基本代码来描述我的实现:
getDirs = (a_path) => {
return fs.readdirSync(a_path)
.filter(file => fs.statSync(path.join(a_path, file)).isDirectory());
}
someCode = () => {
let some_path = path.resolve(process.cwd(), "example");
console.log(getDirs(some_path));
}
在我的项目中,我有:
example/
- test/
- manifest.json
index.js
不知何故,即使应用了给定的过滤器,上述 getDirs 函数仍将 manifest.json 作为目录返回。
其他人有这个吗?有什么想法吗?
其他信息
我已将 getDirs 函数修改为以下内容:
getDirs = (a_path) => {
console.log("getDirs a_path = "+a_path);
let dirs = fs.readdirSync(a_path);
for(let x = 0; x<dirs.length; x++){
let a_dir = path.resolve(a_path, dirs[x]);
console.log(dirs[x]);
console.log(fs.statSync(a_path, a_dir).isDirectory());
}
return dirs;
};
这个的输出是:
getDirs a_path = <pathtoproject>/example
test
true
manifest.json
true
【问题讨论】: