Struggling to delete a persistent file? We were facing the same problem!
In our case, we encountered this issue while working with WSL (Windows Subsystem for Linux) and Python and we wanted to delete a folder.
If you're here just for the solution, here's what you can do:
Step 1: Open Task Manager.
Step 2: Find Python and End Task, then proceed to delete the troublesome files.
Why did this happen and what problems did we face?
So as stated before, we were working with WSL (Windows Subsystem for Linux) on setting up an application locally.
Method 1: We initially attempted to delete the file normally in Windows Explorer, only to be met with a message indicating that the files were in use by another application.
Method 2: We decided to take a bit more assertive approach to delete the file using Comand Prompt. We tried the following commands:
rm C:\Users\User1\software -r -force
Remove-Item C:\Users\User1\software\venv -Recurse
Get-ChildItem C:\Users\User1\software\venv -Recurse | Remove-Item -Force
These commands are used to delete files from the computer or force to delete the files and their subfiles and folders.
However, our attempts were met with the following errors:
The file ‘FileName’ cannot be removed because it is not empty
+ CategoryInfo : PermissionDenied: (file:FileInfo) [Remove-Item], UnauthorizedAccessException
To our relief, the solution to solve this was very simple. Since we were working on an application that made use of Python, the files were being used by Python.exe. By killing the Python.exe in the Task Manager, we were able to delete the files without any issues! Sometimes the hardest problems require the simplest of solutions ;)