You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
640 B
JavaScript
21 lines
640 B
JavaScript
const fs = require('fs');
|
|
module.exports = async function mkdir(filePath) {
|
|
console.log(filePath);
|
|
if (await fs.existsSync(filePath)) {
|
|
console.log('该路径已存在');
|
|
}else{
|
|
console.log('该路径不存在');
|
|
const dirCache={};
|
|
filePath=filePath.replace(/\\/g,"/");
|
|
console.log(filePath);
|
|
const arr=filePath.split('/');
|
|
let dir=arr[0];
|
|
for(let i=1;i<arr.length;i++){
|
|
if(!dirCache[dir]&&!fs.existsSync(dir)){
|
|
dirCache[dir]=true;
|
|
await fs.mkdirSync(dir);
|
|
}
|
|
dir=dir+'/'+arr[i];
|
|
}
|
|
}
|
|
} |