Removing Orphaned Files

Hi there

So my question is whether there is a way to remove “oprhaned” files (Either in Private or Public). As our Frappe deployment has grown, several files have been uploaded and subsequently the linked documents have been deleted or the DocTypes have been changed, regardless, I find that I have quite a bit of files in the private and public folders but I don’t know whether any of these files are actually linked to any documents.

Is there an easy way to find out whether any of the files are not linked by any Frappe documents and can be safely deleted without breaking current documents?

Hi,

Find the File List in the search box. Click on the file that you no longer need. The doctype that it is attached to can be seen. It may be deleted either from the list view, Actions or from the … menu if it has been clicked on.

That won’t work, there are hundreds of orphaned files in the system that are left over and are no longer assigned to any documents.

Since the files in /public and /private do not carry any metatdata referring to their current or former doctype association, it would be necessary to write a script that would produce a list of files that are attached to doctypes, compare it to the entire file list and delete those not in the first list.

I don’t know if the time to develop such a script would be greater than deleting the file manually, or if there (hopefully) is a better solution.

1 Like

Perhaps this will help. You can export a list of files as a csv and possibly operate on that: https://frappeframework.com/docs/user/en/desk/attachments#export-as-zip

There are filters that can be applied that might allow you to create a list of unattached files in the export utility and the file manager as well.

This is likely the only way, I was hoping for a Framework Feature that I couldn’t find, but there isn’t. Looks like I am creating another script that will require multiple backups and restores of my lab site.

How would such a feature work? Find files in /private and /public that are no longer associated with any documents or doctypes , and offer to archive or delete them?

Ideally, yes, in a similar way to bench --site trim-tables