NODEJS文件夹的创建
增加于: v0.1.8
path
<String> | <Buffer>
mode
<Integer>
callback
<Function>
异步创建文件夹方法,除了一个可能的异常以外,没有参数给完成回调。创建的文件夹默认权限即mode默认为
0o777。
fs.mkdirSync(path[, mode])
增加于: v0.1.21
path
<String> | <Buffer>
mode
<Integer>
同步创建文件夹,返回undefined
.
增加于: v5.10.0
prefix
<String>
options
<String> | <Object>
encoding
<String> default = 'utf8'
callback
<Function>
创建一个唯一的临时文件夹。
生成六个随机字符,后面附加一个前缀,以创建一个唯一的临时目录。
创建的文件夹路径作为字符串传递给回调的第二个参数。
可选options参数可以是指定编码的字符串,也可以是指定使用字符编码的具有encoding属性的对象。
例子:
fs.mkdtemp('/tmp/foo-', (err, folder) => { if (err) throw err; console.log(folder); // Prints: /tmp/foo-itXde2 });
注:fs.mkdtemp()方法将追加六个随机选择的字符直接前缀字符串。例如,给定一个目录/tmp,如果打算在/tmp创建一个临时目录,前缀必须结束后平台的具体路径分隔符”(require('path ').sep)。
// The parent directory for the new temporary directory const tmpDir = '/tmp'; // This method is *INCORRECT*: fs.mkdtemp(tmpDir, (err, folder) => { if (err) throw err; console.log(folder); // Will print something similar to `/tmpabc123`. // Note that a new temporary directory is created // at the file system root rather than *within* // the /tmp directory. }); // This method is *CORRECT*: const path = require('path'); fs.mkdtemp(tmpDir + path.sep, (err, folder) => { if (err) throw err; console.log(folder); // Will print something similar to `/tmp/abc123`. // A new temporary directory is created within // the /tmp directory. });
增加于: v5.10.0
prefix
<String>
options
<String> | <Object>
encoding
<String> default = 'utf8'
fs.mkdtemp()的同步版本,返回创建的文件夹路径。
可选options
参数可以是指定编码的字符串,也可以是指定使用字符编码的具有encoding
属性的对象。