Creates a directory, if it does not exist.
Use fs.existsSync()
to check if the directory exists, fs.mkdirSync()
to create it.
代码片段
const fs = require('fs');
const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);
使用样例
createDirIfNotExists('test'); // creates the directory 'test', if it doesn't exist