1
0
Code Issues Pull Requests Projects Releases Wiki Activity GitHub Gitee

fileUtils 创建目录方法更新,解决创建当前文件夹上一级文件夹时报错问题

This commit is contained in:
程序员小墨 2022-07-30 14:49:13 +08:00
parent 6bd81a210f
commit 590e209b2c

View File

@ -1,11 +1,13 @@
const fs = require('fs');
const path = require('path');
const LATEST_DATA_ONLY = process.env.LATEST_DATA_ONLY == true;
// 创建目录
async function createFolder(folderToCreate) {
let currentFolder = folderToCreate.replace(/\\/g, '/');
let parentFolder = currentFolder.substring(0, currentFolder.lastIndexOf('/'));
let currentFolder = path.join(folderToCreate);
let parentFolder = path.join(currentFolder, '../');
// console.log({ currentFolder: currentFolder, parentFolder: parentFolder });
if (!fs.existsSync(currentFolder)) {
// 文件夹不存在,创建文件夹
createFolder(parentFolder); // 保证父级文件夹存在