可能重复:
Check synchronously if file/directory exists in Node.js
例如,我有一个字符串“C:/dev/image.folder”,我想确定,是目录还是文件(同步)。我该怎么办?
提前致谢!
答案 0 :(得分:4)
// Query the entry
stats = fs.lstatSync('/the/path');
// Is it a directory?
if (stats.isDirectory()) {
// Yes it is
}
参见T.J.克劳德的答案在这里:Check synchronously if file/directory exists in Node.js