【发布时间】:2020-02-11 10:58:53
【问题描述】:
我可以打电话
fs.readdirSync("C:\\", { withFileTypes: true })
并获得fs.Dirent 的数组,但它们看起来像
> fs.readdirSync("C:\\", { withFileTypes: true })[32]
Dirent { name: 'Windows', [Symbol(type)]: 2 }
> fs.readdirSync("C:\\", { withFileTypes: true })[21]
Dirent { name: 'pagefile.sys', [Symbol(type)]: 1 }
> fs.readdirSync("C:\\", { withFileTypes: true })[10]
Dirent { name: 'Documents and Settings', [Symbol(type)]: 3 }
所以有一个名称和类型,但类型隐藏在 Symbol(type) 下,我找不到任何信息如何从那里获取它。
当然我可以使用类似的 hack
> x = fs.readdirSync("C:\\", { withFileTypes: true })[10]
Dirent { name: 'DoYourData iCloud Backup', [Symbol(type)]: 2 }
> x[Object.getOwnPropertySymbols(x)[0]]
3
但这似乎很奇怪。
如果它是故意隐藏的,除了名称之外没有任何公开,那么我不明白为什么我们在选项中有一个特殊的标志来获取一个对象而不是简单的字符串。
【问题讨论】:
标签: javascript node.js fs