This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/api/assets/utils/deleteFilesNameStartWith.js
2020-08-03 12:04:07 +02:00

20 lines
558 B
JavaScript

const fs = require('fs')
const path = require('path')
function deleteFilesNameStartWith (pattern, dirPath, callback) {
fs.readdir(path.resolve(dirPath), (_error, fileNames) => {
for (const name of fileNames) {
const splitedName = name.split('.')
if (splitedName.length === 2) {
const fileName = splitedName[0]
if (fileName === pattern && name !== 'default.png') {
return fs.unlink(path.join(dirPath, name), callback)
}
}
}
return callback()
})
}
module.exports = deleteFilesNameStartWith