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

20 lines
558 B
JavaScript
Raw Permalink Normal View History

2020-08-03 12:04:07 +02:00
const fs = require('fs')
const path = require('path')
2020-08-03 12:04:07 +02:00
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)
}
2020-08-03 12:04:07 +02:00
}
}
return callback()
})
}
2020-08-03 12:04:07 +02:00
module.exports = deleteFilesNameStartWith