Windows Guides Feed

New to using the command prompt? Check out the Windows Command Prompt Beginner’s Guide

command prompt Cant Delete a File? Use the Command Prompt [How To]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]

shut explorer Cant Delete a File? Use the Command Prompt [How To]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:

  1. Right Click the Taskbar, choose Task Manager.
  2. Open the Process Tab and locate Explorer in the list.
  3. Right Click the name Explorer.exe and choose “End Process“, confirm if asked
  4. 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).

task run Cant Delete a File? Use the Command Prompt [How To]

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.

  1. Click the File Menu
  2. Choose Run
  3. Type: cmd.exe
  4. 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:

  1. Open Task Manager yet again,
  2. Choose Run from the File menu.
  3. 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.

  1. Click the Start-button and type CMD in the search field (Do NOT press Enter)
  2. 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.
  3. 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.
  4. Highlight the path from the Colon (:) and to the end as shown here)
    CMD highlight 500x53 Cant Delete a File? Use the Command Prompt [How To]
  5. Right-Click the Highlighted part, and choose Copy (or Press Ctrl+C)
  6. Go back to your Command-Window and type: CD\ (This will open the Root Folder)
  7. Now Type: CD\ and Paste in the path using Right-Click, Paste (Ctrl+V will NOT work).
    Like this: CD\testfolder
  8. To make sure you are in the correct folder you can type: DIR. This will show you the folder contents.
    CMD del 500x258 Cant Delete a File? Use the Command Prompt [How To]
  9. 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:

  1. In The Command-Window type:  RmDir /S /Q [Paste in path using Right-Click, Paste], Press Enter.
    Like this: rmdir /S /Q c:\testfolder
    CMD rmdir 500x258 Cant Delete a File? Use the Command Prompt [How To]
  2. Folder and contents will be gone forever.
 Cant Delete a File? Use the Command Prompt [How To]

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...

Web | More Posts (254)


Comments

  • Tyrone Whiston

    Thank you so much for this brief, yet very helpful, tutorial. :)

  • http://www.facebook.com/people/Brittanie-Elizabeth-Brockway/838165412 Brittanie Elizabeth Brockway

    Still said access denied. =/

  • Just_some1_blind

    thanks a lot! old school solutions still help!

  • Lol

    or just restart it!

    • Igorsriga

      I suppose you never have other work happening when you want to delete something…moron…lol

  • Pratik

    Gre8. It worked for me

  • Beeplorizon00

    OMG thx so much man!!!

  • Fanoffans

    Thank you Thomas you are the man!:)

  • Praveen Gupta

    execellent bro…

  • Borzica

    says “access denied”… WTF its a video file… any other suggestions?

    • http://richr.org/ Rich

      Restart in safe mode (usually F8 key as your computer boots) and delete the file.

  • Pachko

    Thank you very much, that was very annoying folder, especially the (.) files. Thanks again!

  • Shrikantnatikar

    who to remove the os in command  fromant 

  • jurgen57

    useless…i guess cmd is not that powerful anyways

  • Ram88

    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.

  • Glwalkergl

    I can’t thank you enough for this! I would have lost all my university work if it wasn’t for this article.

  • http://richr.org/ Rich

    Glad it worked Steve!

  • Pankajthebest27

    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

  • Pankajthebest

    i liked this very much .thanks ——thanks!!!!!!!!!!!!

  • http://www.facebook.com/people/Tazz-Azmi/100000331037871 Tazz Azmi

    it says INVALID switch what shall i do ?

  • http://www.facebook.com/people/Tazz-Azmi/100000331037871 Tazz Azmi

    finally .. thanks i don’t have to actually include f/ q/ and the file is gone for good thanks a lot ..

  • Sandeep Khandolta

    it worked like a charm .. i used tuneup utility and cc cleaner but nothing worked until i found this,,,,,  

    Tx……………………….;)  

  • J Freeman2030

    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. 

  • http://richr.org/ Rich

    Have you tried the same method in safe mode?

  • Jason Winsor

    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

  • Jason

    please help I’ve tried everything on this page. could it be a virus or malicious 

  • Arthur25

    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

  • http://clintjcl.wordpress.com/ ClintJCL

    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…

  • http://profile.yahoo.com/ICLMYRFZYZ6EEXGZ3YTWNGGC3U Kitty

    its amazing experience & 
    ultimate solution .thanks a lot. 

  • Ashish8lko

    result of doing this says access denied in cmd

    • http://richr.org/ Rich

      Can you confirm you ran the command prompt as an administrator?

      • Bbglas007

        I tried this and got the same message running as admin.

  • GeorgeButel

    “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.

    • http://richr.org/ Rich

      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?

  • http://richr.org/ Rich

    Have you tried deleting in Safe Mode?

  • Jimminy

    Thanks a million mate, that seems to have gotten rid of it…Never thought of going old school on it, with DOS. Cheers again

  • 12

    it says the path to the file, and the ” – Acess is denied”

  • Mikee Reb

    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”

  • guest

    Great trick! Wonderfully explained! Thank you!!!

  • Cupofjava2

    It works!  Thank you!

  • http://www.facebook.com/caquito Juan Icaza

    Awesome! You’re a genius my friend! That non delete-able file was getting on my nerves. Thanks!!!

  • bmcom

    Omg i love you! Thank you so much

  • Charliejohnson

    still says acess denied in process of something

    • http://mintywhite.com/ Uvais

      Try in Safe mode

  • http://nemoinsula.wordpress.com KlingonOffTheStarboardBow

    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

  • Blaze-420_saintz4mobb

    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.


Comments
Windows Guides on Facebook
Windows Forums