We recently delivered a project making extensive use of the Drupal Feeds module. While an excellent and hugely time-saving module, it didn't appear to be cleaning up after itself with regard to duplicate files. The various fixes/patches in the issue queue proving to no avail.

As such, we used a simple quick script to clean up automatically. This is attached below and is applicable to Drupal 7.

The script will scan through your chosen directory (and subdirectories), for every file found, it will endeavour to cross-reference that file within your chosen table.
If the file doesn't exist in the tables, it will delete the original file and all it's generated image style files you have defined.

Inevitably, some knowledge of  the inner workings of Drupal 7 will be required but it should be relatively straightforward.

Installation & Configuration   

BACKUP FILES AND TABLES FIRST! - we will not be held responsible for misuse/poor configurations of the script!   

  1. Download the file and rename it as you see fit with a .php extension.
  2. Place the file in the root of your Drupal 7 installation.
  3. Adjust the CONFIGURATION items below to suit.
  4. Run the file (see the safety key note below on the string required).
  5. You can set it via a scheduled task/cronjob to run periodically.

Please feel free to use it, modify it as you see fit.