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.
[Edit]
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
Task Manager
. - Open the Process Tab and locate Explorer in the list.
- Right Click the name
Explorer.exe
and choose “End Process
“, confirm if asked - All open explorer windows will close
NOTE!
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
- Type:
cmd.exe
- Click OK
NOTE!
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.
- Type:
explorer.exe
.
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
CMD
in 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).
Like this:CD\testfolder
- 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
.
Like this: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
like this: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.
Like this:rmdir /S /Q c:\testfolder
- Folder and contents will be gone forever.
About Thomas
Computer geek from the age of 7, which amounts to 30 years of computer experience. From the early days (when every computer company had their own OS) of DOS, Windows 1.0 through Seven...
Thank you so much for this brief, yet very helpful, tutorial. :)
Still said access denied. =/
thanks a lot! old school solutions still help!
or just restart it!
I suppose you never have other work happening when you want to delete something…moron…lol
Gre8. It worked for me
OMG thx so much man!!!
Thank you Thomas you are the man!:)
execellent bro…
says “access denied”… WTF its a video file… any other suggestions?
Restart in safe mode (usually F8 key as your computer boots) and delete the file.
Thank you very much, that was very annoying folder, especially the (.) files. Thanks again!
who to remove the os in command fromant
useless…i guess cmd is not that powerful anyways
Very helpful. Two things though 1) You don’t say what the /s does. 2) In the text you have “Like this: rmdir /S /Q c:testfolder” but in the screen shot you didn’t type the c: . Was able to delete subfolders by going to the folder dir first then leaving out the c: . Thanks for your help.
I can’t thank you enough for this! I would have lost all my university work if it wasn’t for this article.
Glad it worked Steve!
if any folder shows access is denied .you should follow these steps
first open cmd in run
1- type cd if the folder is in c: drive otherwise d: e: f: whatever else
2-type there- cacls sanj /p everyone:f
3- note that sanj in folder name here
hope this will help you thanks
i liked this very much .thanks ——thanks!!!!!!!!!!!!
it says INVALID switch what shall i do ?
finally .. thanks i don’t have to actually include f/ q/ and the file is gone for good thanks a lot ..
it worked like a charm .. i used tuneup utility and cc cleaner but nothing worked until i found this,,,,,
Tx……………………….;)
I got this message: system can not find the file specified.
the file a very long name with 0 bytes, and it is located on desktop. Can not rename, move or delete.
Try to use the “take ownership” trick first, then return here and try using the above help. (http://www.mintywhite.com/windows-7/7security/uac-annoying-add-take-control-to-context-menu-in-vista/)
Have you tried the same method in safe mode?
hmm, tried takeown and the security way, both don’t work . the takeown way says SUCCESS i still can’t delete it. and its a movie
please help I’ve tried everything on this page. could it be a virus or malicious
tried to delete outlook express folder no go it deletes it but upon restart files are back WTF if microsoft can make it so you cant change/delete/or replace files why dont they just make windows a self repairing OS every time you reboot the required files would repair them selves and no hacker could ever stay resident inside of any computer
This is a good solution, but it is not the ultimate solution. Anyone experienced know this already. It’s very easy to see which files have another file open.
In my case, nothing has this folder open. I still can’t delete it. Not even as Administrator. And it’s nothing to do with explorer.exe…
its amazing experience &
ultimate solution .thanks a lot.
result of doing this says access denied in cmd
Can you confirm you ran the command prompt as an administrator?
I tried this and got the same message running as admin.
“CMD does not support UNC paths as current directories” according to my Windows command prompts, being run as administrator, and even in an admin account.
Does this happen when you launch the command prompt or when you run the command? Assuming the second, perhaps you have \ (two back slashes) in your path somewhere?
Have you tried deleting in Safe Mode?
Thanks a million mate, that seems to have gotten rid of it…Never thought of going old school on it, with DOS. Cheers again
it says the path to the file, and the ” – Acess is denied”
Try in safe mode
http://www.mintywhite.com/windows-7/7maintenance/start-windows-safe-mode/
and take-ownership
http://www.mintywhite.com/windows-7/7security/uac-annoying-add-take-control-to-context-menu-in-vista/
for some reason when i try to delete the folder after i paste the path, it says in command prompt “The filename, directory name, or volume label syntax is incorrect”
Great trick! Wonderfully explained! Thank you!!!
It works! Thank you!
Awesome! You’re a genius my friend! That non delete-able file was getting on my nerves. Thanks!!!
Omg i love you! Thank you so much
still says acess denied in process of something
Try in Safe mode
Windows 7 will NOT let me delete a file in System 32/Drivers. It will NOT let me as user with Administrator rights to give full permissions in this folder. Internet stopped working and someone on the internet said replace the raspppoe.sys file, but I can’t delete that or indeed set the persmissions needed.
I also can’t create an account called “Administrator”. It tells me there is one already, but there isn’t – only file with my name and given administrator rights.
Basically it’s crap, isn’t it? OH I can’t delete toe raspppoe.sys file even usuing the DOS prompt
You need to Take Ownership..if you want to rename
http://www.mintywhite.com/windows-7/7security/uac-annoying-add-take-control-to-context-menu-in-vista/
You can’t create Admin acc because there is one already
You need to Enable that Account
<<>>
Open CMD as Admin and Run this Command
net user administrator /active:yes
and reboot..All done
i like the guide. it is great, it helped me a few times before, but this time is different, i am trying to delete a file within a folder, i would delete the whole folder altogether if i could, but my computer freezes and stops responding as soon as i get anywhere near the file or folder i want to delete, for the part where you have to copy the folder address into cmd to delete it, i can’t do that because i cant even get into the folder without freezing. it feels like someone or something is inside my computer messing around, i tryed AVG but it reports no viruses or corrupt files, which i really don’t believe. my computer is running significantly slower since i downloaded this file that i now can’t delete, I have isolated the folder and file from anything else important.
Thank you!! I almost spent a week trying to erase those video files.
thank you….
THANK YOU THANKYOU all day wretling with stupid MKV files easy and simple
thanks soooooooooo much, u da man
The file I need to delete is on C: but my Command Prompt (CMD) opens in S:
How do I delete it? I tried simply copying the file over to S: but it wouldn’t let me do that either. Please help, it’s driving me nuts!
Type c: on the command prompt
thank you so much, you helped me!!! :)
TY so f*cking much i was desperate, stupid file, tried everyting, but now finally YES THANK YOU SO MUCH
Will you please stop swearing? It has never done you any good!
I think just time rmdir /S /Q D:
That didn’t work for me, it still tried to find it in C:
When i tried i got this, pleas help
C:>rmdirsq
C:Program FilesCommon FilesAppleMobile Device Support
The system cannot find the path
specified.
The system cannot find the file
specified.
The system cannot find the path
specified.
The system cannot find the path
specified.
The system cannot find the file
specified.
Thank you very much my friend. Like you, I ‘grew up’ with DOS, except that I was 20 years old at the time. I had cut and pasted the troublesome file into the C: root directory and had been trying to delete it using the cmd.exe prompt. It was your tip about running cmd.exe as administrator that made all the difference. I had no idea that this was an option. Really appreciate the post.