Commit 47cccd4a by chenjinjing

no message

parent 92d20503
const fs = require("fs");
const path = require("path");
//创建文件目录
export async function mkPath(uid, picName) {
let picPath;
let picType;
for (let i = 0; i < 2; i++) {
if ( i == 0 ) picType = `png/${picName}.png`;
if ( i > 0 ) picType = `psd/${picName}.psd`;
let date = new Date();
let imgFile = `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`;
picPath = path.join(`res/${imgFile}/${uid}/${picType}`);
//转变成数组,如 ['res', 'imgFile', '1212']
let parts = picPath.split(path.sep);
for(let i = 1; i <= parts.length; i++) {
//重新拼接成 res res/imgFile res/imgFile/1212
let current = parts.slice(0, i).join(path.sep);
fs.access(current, (err) => {
if(err){
console.log("文件目录不存在")
fs.mkdir(current, (err) => {
if (err) {
console.log('创建文件目录失败');
} else {
console.log('创建文件目录完成');
}
})
} else {
console.log('文件目录已存在')
}
})
}
}
console.log(picPath);
return picPath;
}
function test(uid, picName) {
// let suffix = picName.slice(picName.lastIndexOf("."));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment