File trash (Orphaned file locator)

Reports ::: report_filetrash
Maintained by Barry Oosthuizen
Utility for listing, downloading and deleting orphaned files (file no longer referenced in the files db table but still present in the Moodle data and/or backup directory
Latest release:
704 sites
35 fans
Current versions available: 2

The files in the Moodle data folder and backup folders are referenced in the "files" table in the database.  If you view the folders themselves you will find the sha1 hash code under which the file has been saved and referenced in the database.  If you have any orphaned files (files no longer referenced by the database but still present on your disk) it will be very difficult to find them.  This utility enables you to immediately receive a list of orphaned files together with the file type and size.  You can download the file to see what it is (the name is a sha1 hash so that won't give you any clues).  If you are happy to delete the file you can select it with the checkbox next to it's description and click delete.  You will be asked for confirmation before the file is finally deleted.

Please note:  This plugin requires the fileinfo PHP extension


Screenshot #0


Barry Oosthuizen (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Sat, Oct 24, 2015, 4:53 AM
    For Justin an Geir, i got the same problems and correct it by adding this line in settings.php file:

    $ADMIN->add('reports', new admin_externalpage('report_filetrash', get_string('pluginname', 'report_filetrash'), "$CFG->wwwroot/report/filetrash/index.php",'report/filetrash:view'));

    (base on report/security and modify for report_filetrtrash)

    Now i get the menu but still get "Section error" when i try delete files.
  • Sat, Oct 24, 2015, 11:14 PM
    Thanks for the reports and suggested fix. I have updated the plugin now. Hopefully this should fix the section error problems and make the report link show up.
  • Mon, Oct 26, 2015, 8:53 PM
    Thank Barry, its working fine for me on moodle 2.8
  • Tue, Dec 8, 2015, 1:31 PM
    I get the following error when I run the plug-in:

    Exception - RecursiveDirectoryIterator::__construct(/mnt/zion/neo/moodle_courses/student_vet): failed to open dir: No such file or directory

    Is there anything I can do to fix it?

  • Tue, Dec 15, 2015, 10:00 AM
    Hi Petras, we had a similar error and found we had a backup directory stipulated in our Admin/Courses/Backups info that didn't exist. So somewhere in your settings that path is listed but doesn't exist (isn't necessarily the backups). Maybe you could create the folder path or find the missing reference to it under the Administration area?
  • Mon, Dec 21, 2015, 11:17 PM
    I have installed this plugin on our Moodle, it has brought up a huge list of backup files (.mbz) - around 1940 to be precise. I can click on the link and download these so they are present. When I follow the directory path they are not there, also when I try to delete it through the plugin it says "There was a problem deleting the following files" and makes me continue onto the report. Any ideas where these backups are, and why they aren't deleting through the plugin? Would love to clear them off the disk.
  • Wed, Apr 20, 2016, 12:45 AM
    Very helpful, thanks!
    Any chance of including a bit more info from the file (like mod date), and the option to 'table-ize' and/or sort the list? I'm willing to help a bit if that's of interest...
  • Fri, Jun 10, 2016, 5:21 AM
    Hi Admin Hesston College,

    Please feel free to help out if you have any code to contribute. It would be much appreciated.
  • Thu, Nov 24, 2016, 6:42 AM
    Can this plugin be used in 3.1? If not, is there any likelihood the plugin will be updated for 3.1+?
  • Fri, Dec 9, 2016, 7:43 PM
    To whom it may concern ...
    ...guess we have a typo in "filetrash/lang/en/report_filetrash.php".
    It must be
    $string['filetrash:view'] = 'View the file trash report';
    instead of
    $string['filtetrash:view'] = 'View the file trash report';

  • Wed, Jan 25, 2017, 1:28 AM
    How does this work exactly? Here's what I've tried:
    1. I created a course
    2. I created a File activity and uploaded a large video file. I can confirm that file exists in the filedir by following the hash.
    3. I then deleted the course. I can confirm it's deleted in mdl_course table. I also can confirm that the file still exists in the filedir.
    4. I run the filetrash plugin. It says "There are no orphaned files in the filedir directory of your moodledata folder"

    What does orphaned file mean? I have a file in filedir that should have no database reference considering the course is deleted. Is that not the definition of orphaned file?
  • Wed, Jan 25, 2017, 2:12 AM
    Hi D Riddel, An orphaned file is a file which is in the filedir but not in the database. It is possible that the file you uploaded is still in the database in which case it is not orphaned
  • Wed, Jan 25, 2017, 3:07 AM
    Hi Barry Oosthuizen,
    Thank you for the help! You're right, there's still a record in the database. It's where filearea="draft". Apparently, draft files don't get deleted from the database when a course with the file is deleted. I'm guessing that the cron cleans up the draft files over time...
  • John Jackson
    Thu, May 16, 2019, 12:11 AM
    Though this plugin is only certified to Moodle 2.9, I just installed it on a 3.5.5 Moodle installation, and it appears to work without any errors.
  • Fri, Sep 20, 2019, 10:14 PM
    This plugin does *not* work for me on 3.5.7. I keep getting database exceptions and timeouts.

1 2 3
Please login to post comments