So the thing is that, I'm storing files of other guys on my server that are mp4 but I need to make sure to delete that later on but sometimes the files remain.
So I want to do something that will detect if any .mp4 file is found in the folder if yes then I can remove it using unlinkSync.
I don't know the filename, that's why I want the system to figure it out
Hope you guys can help?
CodePudding user response:
You can use readDir
to read all filenames in a folder. Afterwards you can check the file ending:
const testFolder = './tests/';
const fs = require('fs');
fs.readdir(testFolder, (err, files) => {
files.forEach(file => {
console.log(file.includes(".mp4"));
});
});