const fs = require('fs')
//重置img文件夹
const toolsResetImgDir = async (req, res) => {
const { dirPath = 'D:/temp/yuying/video/grade1/chinese1' } = req.body
let imgDirPath = dirPath + '-img'
const isExistImgDir = fs.existsSync(imgDirPath)
if (isExistImgDir) {
//删除文件夹
fs.rmdirSync(imgDirPath, { recursive: true })
}
//创建文件夹
fs.mkdirSync(imgDirPath)
//创建文件
fs.writeFileSync(imgDirPath + '/截图.png', '1')
res.send({
code: 200,
data: {
dirPath,
isExistImgDir
},
message: '成功'
})
}
//删除要更新的图片
const toolsDeleteImg = async (req, res) => {
const { dirPath = 'D:/temp/yuying/', filename } =
req.body
const isExistImg = fs.existsSync(`${dirPath}${filename}`)
if (isExistImg) {
//删除文件
fs.unlinkSync(`${dirPath}/${filename}`)
}
res.send({
code: 200,
data: {
dirPath,
filename
},
message: '成功'
})
}