New to using the command prompt? Check out the Windows Command Prompt Beginner’s Guide
Have you ever experienced that windows won’t allow you to delete a file, presumably because some service or dll is still using it ? Even when you know for a fact that it’s not in use ? Or maybe you have tried to delete a folder, but you couldn’t because a “File in the selected folder is still in use by Windows” ?
Oh, I can hear you: “yes, but I use the “take ownership” function that I’ve added to my Context menu”. ALAS, Sometimes not even that will work – what then ? Do you have to Reboot your computer to be able to delete that file ?
Earlier, Harry had an article about the Command Prompt (read it here) and his top ten commands. One of those were the command we are looking to use now: DELETE (DEL).
The Command Prompt (cmd.exe) is what’s left of the old DOS (Disk Operating System) and some of us are old (shudders) enough to have actually used it as our main OS. Okay, enough of that.
As you can see from the comments below, some need to shut down the Windows Explorer (Not Internet Explorer) before succeeding to delete troublesome files. I recommend you first open the Command Prompt BEFORE shutting down Explorer even though it is possible to start it after. To shut down the Explorer window, you need to start Task Manager:
- Right Click the Taskbar, choose
- Open the Process Tab and locate Explorer in the list.
- Right Click the name
Explorer.exeand choose “
End Process“, confirm if asked
- All open explorer windows will close
All open programs will still be running (even task manager). You can still access the programs using ALT+TAB (or Windows + TAB).
Access the Command Prompt after shutting down Explorer
If you didn’t open the Command Prompt before shutting down Explorer, you may still access it by opening the Task Manager (which should still be running). Use ALT+TAB to flip through the running programs to open it.
- Click the File Menu
- Choose Run
- Click OK
Should Task Manager by any chance be unavailable, you may open it by clicking CTRL+ALT+DEL, and choose Start Task Manager from the Menu.
Restart Task Manager
Once finished deleting your files you may restart the Explorer again lik this:
- Open Task Manager yet again,
- Choose Run from the File menu.
Thanks to Jothe3inv and Johnny for bringing us this extra tip.
Delete Troublesome files
This tutorial requires that you open the Command prompt as an Administrator and that you can access the folder from Windows.
- Click the Start-button and type
CMDin the search field (Do NOT press Enter)
- When you see the program in the list, right-click on cmd.exe and choose Run as Administrator. This will open the Command Prompt Window with Administrative Privileges.
- In you Windows Explorer, open the folder you want to delete or remove a file from. Click on the Adress-field to reveal the true folder path.
- Highlight the path from the Colon (:) and to the end as shown here)
- Right-Click the Highlighted part, and choose Copy (or Press Ctrl+C)
- Go back to your Command-Window and type:
CD\(This will open the Root Folder)
- Now Type:
CD\and Paste in the path using Right-Click, Paste (Ctrl+V will NOT work).
- To make sure you are in the correct folder you can type:
DIR. This will show you the folder contents.
- To delete the file causing you problems, type:
DEL[filename] /F /Q.
DEL filename.dat /F /Q.
The F means: Delete File even IF it’s reported as Read Only.
The Q means: you don’t have to Confirm.
If you want to delete all files in the folder, you can use wildcards instead of Filename
DEL *.* /F /Q
Delete Folder which Contains Troublesome File(s)
Sometimes you need to delete the problem file before you delete the folder, but this is what you do:
Follow steps 1 through 6 above then continue here:
- In The Command-Window type:
RmDir /S /Q[Paste in path using Right-Click, Paste], Press Enter.
rmdir /S /Q c:\testfolder
- Folder and contents will be gone forever.