Clean out unused media items from Umbraco media folder
Wednesday, September 03, 2008 5:15:14 PM (GMT Daylight Time, UTC+01:00)
When uploading some new media items for a client today we noticed that if you selected "Remove" before saving, it doesn't actually remove the file from the FileSystem. Having a quick look around the forums I saw there are a few posts already pointing this out so I thought I'd fix it.
This is a little application that simply checks the media items in the database and then compares it against a folder you select on your machine. If the file is in use according to the database then it's ignored otherwise it will remove it.
- Enter your server's login details
- Click "Test Connection"
- Select the relevant database from the drop down
- Check the "Media Folder Name" matches your Umbraco's installation
- Locate your Media Folder on your computer
- Click "Check Media Folder" -this will then list all the orphan files
- If it looks right, click "Delete" -with caution
- Job done
There are a few checks in place to avoid mishap but it's not 100% foolproof as I needed something rough and ready to sort a couple of installations out. If this is something that's seen as useful I'll extend it a touch, some ideas I've got already:
- Check that the selected media folder matches that of the database
- Check that the media id's are the same (to avoid wiping another installation)
- Save config settings for easy re-use
- Use webservices rather than a direct connection to the database
- Enable FTP useage
Please note: I accept no responsibility if anything was to go horribly wrong with this. I would backup your folder first just in case!
You can download the MediaFolderCleaner application here