if (fs.existsSync(rootPath)) { //先删除文件 rootPath文件夹路径
let files = fs.readdirSync(rootPath);
files.forEach(function (file, index) {
var curPath = rootPath + "/" + file;
if (fs.statSync(curPath).isDirectory()) { // recurse
fs.rmdirSync(rootPath);
console.log("文件夹");
} else { // delete file
console.log("删除文件", file);
fs.unlinkSync(curPath, function (err) {
if (err) throw err;
});
}
});
// fs.rmdirSync(pathImg);
}
//判断文件路径是否存在,如果不存在,创建文件夹
function mkdirsSync(dirname) {
if (fs.existsSync(dirname)) {
return true;
} else {
if (mkdirsSync(path.dirname(dirname))) {
fs.mkdirSync(dirname);
return true;
}
}
}