Friday 19 May 2017

Delete all files in a certain directory that there names start with a certain string in node js

I want to delete all files that there file names start with the same string in a certain directory, for example I have the following directory:

public/
      profile-photo-SDS@we3.png
      profile-photo-KLs@dh5.png
      profile-photo-LSd@sd0.png
      cover-photo-KAS@hu9.png

so I would like to apply a function to delete all the files that start with the string profile-photo to have at the end the following directory:

public/
      cover-photo-KAS@hu9.png

I am looking for function like this:

fs.unlink(path, prefix , (err) => {

});



via Karim

No comments:

Post a Comment