Drupal 9 and 10 do not delete any files automatically, so file cleanup may be needed. When you delete content that uses something in the Media Library (such as an event with an image field), the media item is not deleted along with the content. (This is different from Drupal 7, which deleted some files automatically if they were not being used.)
Ask: Does this file need to be deleted or replaced?
If you need to replace a file with an updated version, visit Manage > Content > Media tab, find and edit the appropriate media item, and use the Replace file field instead. (Check the box next to Keep original filename.)
Deleting Media (in the Media tab)
- Visit Manage > Content > Media tab
- Click the Edit button next to a media item in the list.
If the media item is used somewhere else on the site, it should have a yellow bar like this:
Image- Click the link in the yellow bar or click the Usage tab to see content that uses the media item.
- If there is no yellow bar:
- Double check that the file is not displayed/referenced in the sidebar/footer of the website (these instances might not be detected as "use" and you may need to rely on your memory or a visual check).
- Select Manage > Content > Search & Replace Scanner tab.
- UN-check the boxes next to Case sensitive search and Match whole word.
- Enter the filename or a portion of the filename in the Search for field.
- Press Search.
- If any matches are found, check whether they are referencing the same file. Eliminate any references to the file before proceeding.
- Click the Delete link or tab. Confirm that you really want to delete the media.
About the Files tab
The Files tab consists of files that Drupal knows about, which may or may not have an associated Media item.
- In some cases, media items were not created for all files when sites were migrated to Drupal 9.
- Prior to May 2023, media items could be deleted without deleting the file they were associated with (leaving behind an orphan file).
The Files tab "Used in" column can be very misleading -- even "Used in: 0 places" may not be true. The steps below include additional checks to reduce the chance that deleting a file will leave behind broken references.
Deleting Files (in the Files tab)
- IMPORTANT - Visit the Media tab and go through all the steps for Deleting Media first. If the file is attached to a media item, it's best to delete the media item and the file together.
- If you're sure there is not a Media item that uses the file you wish to delete, double check that the file is not displayed/referenced in the sidebar/footer of the website (these instances might not be detected as "use" and you may need to rely on your memory or a visual check).
- Select Manage > Content > Search & Replace Scanner tab.
- UN-check the boxes next to Case sensitive search and Match whole word.
- Enter the filename or a portion of the filename in the Search for field.
- Press Search.
- If any matches are found, check whether they are referencing the same file. Eliminate any references to the file before proceeding.
- Select the Files tab.
- Search or browse to find the file.
- Check the "Used in" column -- it should be showing 0 places.
- Press the Delete button. Confirm that you really want to delete it if prompted.