Most efficient way to delete multiple uploaded files from the project directory

What is the most efficient way to delete multiple uploaded files from the project directory when the file path of these files got deleted from the database?

It is more of a generic question than related to AdonisJs directly.

If you don’t have the filename, then you will filter for the files that already exists in the database and then delete the one’s missing.

  1. Do a select of file names from the database (this will get you an array).
  2. Use a package like https://www.npmjs.com/package/klaw to collect all files paths from the disk.
  3. Find the diff between both the arrays