Out of the box, Sitecore XP does not support moving, renaming, and deleting file system media associated with the Media Library items. It is considered potentially dangerous because files cannot be restored in case of an error. For example, a user might not know if the file to be deleted is used elsewhere on the website.
As a solution, consider one of the following options:
- Change the approach for storing media items (recommended). For example, starting from Sitecore XP 9.3 Initial Release, Sitecore Blob Storage allows users to store media files in Azure Blob Storage, thereby reducing the hosting costs and improving performance.
- Create a custom handler for the item:deleting event to delete the required file. In the handler, get the name of the file from the FilePath field (if it is present in the item and not null) and use the Sitecore.IO.FileUtil.Delete method to delete the file.
- Delete physical files manually from the file system.