From 2ee94b6f84ede676187c5ba75f46357079dd108a Mon Sep 17 00:00:00 2001 From: YuJian Date: Fri, 22 Jul 2022 16:37:44 +0800 Subject: [PATCH] vault backup: 2022-07-22 16:37:44 --- 随时随地/Nodejs 文件系统学习笔记.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/随时随地/Nodejs 文件系统学习笔记.md b/随时随地/Nodejs 文件系统学习笔记.md index 96d3a2c..e638dc7 100644 --- a/随时随地/Nodejs 文件系统学习笔记.md +++ b/随时随地/Nodejs 文件系统学习笔记.md @@ -220,4 +220,15 @@ const ensureParentDirectory = (filePath: string) => { ### 创建临时目录 -在有些场景,我们需要创建一个临时文件夹,那么这时我们可以使用 `fs.mkdtempSync(pathPrefix, options?)`,它hui'chu'a \ No newline at end of file +在有些场景,我们需要创建一个临时目录,那么这时我们可以使用 `fs.mkdtempSync(pathPrefix, options?)`,它会在 `pathPrefix` 目录下创建一个随机6位字符串作为名称的目录,并返回路径 + +如果我们需要在系统的全局临时目录中创建临时目录,我们可以借助 `os.tmpdir()` + +```typescript +import * as os from "node:os"; +import * as fs from "node:fs"; +import * as path from "node:path"; + +const pathPrefix = path.resolve(os.tmpdir(), "my-app"); +const tmpPath = fs.mkdtempSync(pathPrefix); +``` \ No newline at end of file