首页 > Web开发 > 详细

Node.js检查文件是否存在

时间:2016-11-06 22:28:03      阅读:314      评论:0      收藏:0      [点我收藏+]
"use strict";

const fs = require("fs");

//fs.mkdir("test", function (err) {
//    if(err) throw err;
//    console.log("创建成功");
//})

//fs.rmdir("test", err => {
//    if(err) throw err;
//    console.log("删除成功");
//})


//fs.exists(‘test‘, (exists) => {
//    if(exists) {
//        console.log("存在");
//    }else{
//        console.log("不存在,创建文件夹");
//    }
//});


//使用access检测文件夹是否存在
//6.xxx使用fs.constants.F_OK
//4.xxx使用fs.F_OK
fs.access(‘test‘, fs.F_OK, (err) => {
    if(err) {
        console.log("文件夹不存在");
        return;
    }
    console.log("文件夹存在");
});
4.xxx使用fs.F_OK
6.xxx使用fs.constants.F_OK

Node.js检查文件是否存在

原文:http://www.cnblogs.com/yychz/p/6036372.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!