Windows系統
學習nodejs創建目錄命令:mkdir
var fs = require('fs'); fs.mkdir('./tmp/test',function (err) { if(err){ return console.error(err); } console.log('創建目錄成功!'); });
報異常:
D: ode_learn>node mkdir_test.js { Error: ENOENT: no such file or directory, mkdir 'D: ode_learn mp est' errno: -4058, code: 'ENOENT', syscall: 'mkdir', path: 'D:\node_learn\tmp\test' }
問題在哪呢?
原來,nodejs創建目錄需要逐層創建,因爲我當前目錄下,不存在tmp目錄,所以正確的做法應該是——
- 先創建 tmp 目錄
- 再創建 test 目錄