This error message appears because the file you want to delete is open in another application or program. If you are facing a similar situation and still don’t know how to get rid of these undeletable files, try applying the 6 methods I will guide you through below.
Method 1: Close the Application

Before diving into more complex methods, let’s start with the simplest and most straightforward approach. If you can identify which application the undeletable file is open in, simply close that application. For instance, you can’t delete a Word file because you have it open, or you can’t delete an audio or image file because it’s being used in video editing software like Adobe Premiere or Camtasia. Once you close the application, try deleting the file again.
Method 2: Restart the Computer

Although restarting the computer may not be the most convenient method, it is easy and does not require any experience with Task Manager or third-party applications. Restarting the computer also clears the RAM and resolves annoying errors you might be facing. Therefore, try this method if you don’t want to delve too deeply into solving these issues.
Method 3: End the Application via Task Manager
The success of the restart method in Method 2 is due to your system shutting down all ongoing tasks or processes. However, this also means that all other important applications you are using will close as well. If you don’t want to restart your computer every time you encounter the message “cannot delete because the file is open in another program,” you can separately end that application within Task Manager.
Press Ctrl + Shift + ESC to open Task Manager, then find the application you used to open the file you want to delete, right-click on it, and select End task.

Method 4: Change File Explorer Task Settings
By default, File Explorer starts and runs all its windows in a single task, which is explorer.exe or Windows explorer.exe. However, it is possible that your settings have forced File Explorer to operate in separate tasks, causing conflicts between those tasks.
Press Windows + E to open File Explorer, then select View > Options > Change folder and search options.

A new window will appear; select the View tab. Find and ensure that the Launch folder windows in a separate process option is not checked.

If you access the View tab and see that the Launch folder windows in a separate process option was unchecked from the beginning, you might try checking that box to see if the error is resolved.
Method 5: Disable the Preview Pane Feature in File Explorer
The Preview Pane feature in File Explorer can cause the “cannot delete because the file is open in another program” error.
Press Windows + E, then press the Alt + P key combination to disable the Preview Pane feature.

After disabling the Preview Pane, try deleting the file again to see if the error persists.
Method 6: Boot Windows in Safe Mode

If the above methods do not work, you can try one last resort: booting Windows in Safe Mode. If you are not aware, Safe Mode is a restricted mode of Windows. Specifically, when you run Windows 10 in Safe Mode, everything that may cause software errors is disabled. In other words, any applications that are not default Windows applications cannot run.
First, press Windows + I, select Update & Security > Recovery. Under Advanced startup, select Restart now. Then, choose Troubleshoot > Advanced Options > Startup Settings > Restart. When the computer restarts, you will see the Startup Settings screen, from which you can select Safe Mode. Once you enter Safe Mode, try deleting the file once more.
Wishing you success!
Source makeuseof