'use strict'; //這是一個簡單的應用 var path = require('path'); var fs = require("fs") ; global.l = console.log; //檢查某個目錄是否存在 var stat = fs.statSync(path.join(__dirname,'content')); l(stat.isDirectory());//為true的話那么存在,如果為false不存在 //檢查某個文件是否存在 try{ fs.statSync(path.join(__dirname, 'content/a1.txt')); //如果可以執行到這里那么就表示存在了 console.log('haode'); }catch(e){ //捕獲異常 }