How to Delete Files

Complexity Level: Intermediate

This is an intermediate topic. You will need to possess some basic understanding and have some experience with Drupal content editing.


Let's say you've removed a file from a page by deleting the link, or by replacing that link with a newly uploaded file. However, people are still finding the old file by way of outdated links or via Google. How do you remove this old file so people can't find it any more?

The short answer is this: the same way you uploaded the file. 

Table of Contents

Delete Files Via the File Manager (IMCE)

In the same way the you upload PDF files, documents and images with the File Manager (see Inserting PDFs and Other Documents), you can find files and delete them.

Note: In Drupal 10 you can also see where and how files are used on the site by going to Content and clicking the "File" tab. In fact, you may want to do this first. You can follow my instructions for finding where files are used below.

Step 1: Create a Basic Page

We won't end up saving the page; this is just a way for us to access the File Manager.

Step 2: Upload a File

Click the Link icon.

Then click the blue 'Open File Browser' text.

Step 3: View Files to Remove

This brings you to the File Uploader/Manager, where you can add and remove files.

You can delete files from here. Look for the file you want to delete. You may have to look for it in the folders, such as inline-files.

Step 4: Delete File

Click on it to select it, then click the "Delete" option at the top of the file manager.

Note: If the file is at use anywhere on the site, the file manager will not allow you to delete it (see my section below, "Figuring out where Files are on the Site"). 


Please be careful when deleting content. If you delete something you did not intend to, you will have to re-upload it to get it back. 

Possible Issue with Revisions

Note: If you try to delete files with this method and you receive an error, it's also possible the file is linked to a revision of a page. IMCE will treat revisions the same as other content, and will not remove linked files.


To solve this problem, delete the revisions with links to the file you want to remove. When you delete the revision, the file will also be removed and manually deleting the file will not be necessary. 

If you don't see a "Revisions" tab with your content, please put in a helpdesk ticket to the web team:

Step 5: Done!

You can exit out of the File Manager and Basic Page.
You don't need to save the Basic Page; it was just a way for us to access the File Manager.

Figuring Out Where Files are Used on the Site

In your site you can see all the files that are uploaded on the site, and what specific pages are linking to them.
This could be useful to you if you are trying to decide what version of a file to remove.

Step 1: Finding Files

Under "Content," click on the tab called "Files" 

It's all the way to the right. If you don't see it then you don't have sufficient permissions. You can talk to the person from your department who is in charge of the website and ask for their help.

Step 2: Searching By Title

When you search for a File using a keyword or partial title, you can see all the files uploaded, and what pages they are being used on, if at all.
In the below example, when I searched for "Hague," I found several files. Some are not being linked to at all, as indicated by the right-most column. 

Step 3: Viewing the Files

Click on the file to view it, or mouse over it to see its location in the file structure

You can view the files by clicking on them, and mouse over them to see the url of the file, and learn if the file is in any special folder, other than sites/default/files.
For example, the first file below is also in sites/default/files/inline-files, which I can see by looking at the url at the bottom of the browser.

So going back to my first set of instructions, if this was the file I wanted to remove, I would go into the File Manager, look in the Inline Files folder, and remove that. (Except that the File manager probably wouldn't let me remove the file because it is being used in two places. So I would have to go into those pages and remove those links from them first.)

Note about Deleting Files and Drupal

There is a known issue with Drupal 8 sites and deleting files. Files that are being tracked by the revisioning functionality-- the one that allows site admins to revert to a previous version of page-- can't be deleted. 

Your site's content administrator or web team members may have to delete the revisions of a page (under the revisioning tab) to release the file for deletion. Even still, it may take database surgery to fully remove some files.

As of February 2018 I am turning off revisioning for Personnel pages only, but the old revisions will still exist and will therefore still hold onto old files. 

Web team members can view the /wiki/spaces/WT/pages/27232283 document for more information.