您的位置:首页 > Web前端 > Node.js

node.js中检查目录是否存在

2017-12-19 08:43 731 查看
function checkDirExist(path)
{
try
{
return
fs.statSync(path).isDirectory();
}
catch
(e) {

if
(e.code
==
'ENOENT')
{ // no such
file or directory. File really does not exist
console.log("File
does not exist."
);
return
false
;
}

console.log("Exception
fs.statSync ("
+ path +
"): "
+ e);
throw
e;
// something else
went wrong, we don't have rights, ...
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  node.js file