backend: PUT /users - Supprime les anciens logo

This commit is contained in:
Divlo
2020-04-07 17:15:01 +02:00
parent 5bf9a2ade6
commit 3ed605af1b
2 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,20 @@
const fs = require("fs");
const path = require("path");
function deleteFilesNameStartWith(pattern, dirPath = __dirname) {
// Get all file names in directory
fs.readdir(path.resolve(dirPath), (err, fileNames) => {
if (err) throw err;
console.log(dirPath);
// Iterate through the found file names
for (const name of fileNames) {
// If file name matches the pattern
if (name.startsWith(pattern)) {
console.log(name)
fs.unlinkSync(path.join(dirPath, name));
}
}
});
}
module.exports = deleteFilesNameStartWith;