"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