首页 > 代码库 > Node.js检查文件是否存在
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
Node.js检查文件是否存在
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。