Node.js检查文件是否存在


"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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM