fileUtils 创建目录方法更新,解决创建当前文件夹上一级文件夹时报错问题
This commit is contained in:
parent
6bd81a210f
commit
590e209b2c
@ -1,11 +1,13 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const LATEST_DATA_ONLY = process.env.LATEST_DATA_ONLY == true;
|
const LATEST_DATA_ONLY = process.env.LATEST_DATA_ONLY == true;
|
||||||
|
|
||||||
// 创建目录
|
// 创建目录
|
||||||
async function createFolder(folderToCreate) {
|
async function createFolder(folderToCreate) {
|
||||||
let currentFolder = folderToCreate.replace(/\\/g, '/');
|
let currentFolder = path.join(folderToCreate);
|
||||||
let parentFolder = currentFolder.substring(0, currentFolder.lastIndexOf('/'));
|
let parentFolder = path.join(currentFolder, '../');
|
||||||
|
// console.log({ currentFolder: currentFolder, parentFolder: parentFolder });
|
||||||
if (!fs.existsSync(currentFolder)) {
|
if (!fs.existsSync(currentFolder)) {
|
||||||
// 文件夹不存在,创建文件夹
|
// 文件夹不存在,创建文件夹
|
||||||
createFolder(parentFolder); // 保证父级文件夹存在
|
createFolder(parentFolder); // 保证父级文件夹存在
|
||||||
|
Loading…
Reference in New Issue
Block a user