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

Free PC tips by email

Search Windows Guides




Comments

  • Nikki

    uhhh why we dont have a shorter version or sum -_ i cant delete a file and its 8 gb !

  • Troublesome..

    I’m trying to remove this damned winrar, but when i type /S /Q c:WinRAR it says I can’t delete it since it’s being used by another procces? Help ?

  • max

    it keep telling me access denied

  • LPHeadstrong

    THANK YOU! Some empty folder wouldn’t delete (rather it would through CMD but was always in Explorer). RMDIR worked anyway! Simple solution but thanks again!

  • sufian

    Thank you very mutch ^&^

  • adrian

    thank you o master! I’d never thought to stop explorer before and that cracked it! quite often I get weird files I can’t delete and I know I fix the permissions but no matter what Vista won’t let me delete them. thank you thank you thank you!

  • Tim Murphy

    How do I go about deleting troublesome files from an external drive??? I have tried this method and can’t get it to work???

  • Gemma

    Thank you so muchi used the cmd thing through administrator thanks

  • Maddy

    Awesome info to delete files as well as folders

  • Mitya

    thanks very much!!! worked perfectly deleted the troublesome folder easily)

  • brandy

    Thank you a LOT!!!! by the way, if you want to delete certain file , you dont need to access that directory, you can just type ”DEL C:Directoryfile.exe” and it will delete file.exe. :)

  • Feño

    Thanks, worked perfectly for me!

  • Kaki

    It says >>> Access is Denied .

  • Adrinn

    I tried using this method, but cmd kept saying Access is denied even though I run it as administrator. Any suggestions?

  • Steve Paul

    if it says you can’t delete the file because its being used by windows explorer, i found the easiest way to delete it is to follow the steps above, but before doing so, open task manager and keep it open. go to the processes tab. end the explorer.exe process. then in task manager click the file menu and click on new task. run cmd and follow the steps above. make sure u have the file name already on your clipboard before u start this if its a longer filename to make it easier. when you finish go back to task manager, click file, new task and type explorer. u should b good to go

  • http://www.facebook.com/profile.php?id=594406076 Mohamed Hassan

    thanks guys :)

  • http://www.facebook.com/people/Jesus-Jones/100001654436827 Jesus Jones

    still unable to delete the file. There are 2 “files” with a size of “0″ with no file extension (.mp3) and I cannot delete them. When I try to delete them in windows or cmd.exe as admin it says file not found or cannot find this item. They were left after downloading a vid to mp3 via the web/youtube. Been there for months now – anyone have another option for a file that “really isnt there” ???????

  • http://richr.org/ Rich

    Type D: at the command prompt to switch to the D drive.

  • http://twitter.com/VBuloff Vlad Buloff

    tanxxx a lot!

  • Simone

    THANKYOU so much for this post. I had weird torrent files that would NOT go away. I couldn’t rename, delete, open or move them. After playing around with your instructions, I have success!
    ‘Rmdir’ didn’t work for me for every folder, but once the problem files were deleted, I opened explorer again and deleted the empty folders in explorer with no issue. I hope this helps someone else. Thanks again!

  • http://www.facebook.com/vinod.bhoir.73 Vinod Bhoir

    Thanx man my file is deleted without using command prompt I just End process explorer and open cmd after i restart explorer.exe from taskbar …..after file has deleted…(Windows vista).

  • Dybus

    It’s gone! Thank you so much!!!

  • gustech

    I deleted a .psd file using cmd with explorer off. Now the file owning program (photoshopelements) won’t run anymore.

  • raven@gmail.com

    perfect….thanks

  • Steven Kennedy

    It appears that DOS doesn’t handle file names that include spaces. Is there any way to get around that?

    • http://richr.org/ Rich

      Steven, you can enclose the file name with double quotes. If you’re referencing the file with a path i.e. C:FolderFile Name.txt, be sure to put the whole path in quotes.

  • PsychoMan

    WOW thanks man for this i got rid for a file that gave me alot of trobles

    thank you

  • fabulous007

    thank you so much for this brilliant advice! I was having such trouble deleting a video file, but this sorted out the problem in no time! very grateful indeed :)

  • o

    i still get access denied

  • http://www.facebook.com/kenneth.cct Kenneth Cct

    doesnt work

  • DC

    Here’s an alternate method to opening the command prompt directly from the base folder that you’re performing the operations within. All you have to do is hold the shift key and right click within the whitespace of the base folder. The right-click context menu will then contain an option to open the command window directly within the folder, thus bypassing the need to open within the system partition and manually direct the prompt to your base folder. See the image attached.

  • DBoydNL

    Sucks when the instruction “DEL[filename] /F /Q” contains an error (space is missing after “DEL”, which forces you to retype the command (and read the example) to get it right. DOS has indeed been too long ago for me to recognize the mistake immediately. The devil’s in the details. Got it to work though (when I added a wild card for the non existent extension), thanks!

    • http://richr.org/ Rich

      I updated the article and put a space in there :)

  • Amanda Lynn

    You just saved me so much trouble!!! I love you!!!

  • jay den

    Long path tool can be helpful on this situation

  • Mahmudur Rahman

    Thanks for your tips. I resolve my problems without shut window explorer. Thank you again. Its really work.

  • Dylan

    What if forler I wan’t to delete is not on local disc C, but in external disc G

    • Seneral

      I put a random disc in my drive and could access it with simply ” D: ” instead of ” CD ” just pick your discs path


Computer tips in your inbox
Sign up for the Windows Guides newsletter to get PC tips and access to free Windows books (More details)

Enter your email address:
 

Popular Guides

See which sites have been visited on your PC (even if private browsing mode is used)

Create a Windows 7 System Repair Disc

Best Free Anti-malware

Hibernate vs. Sleep vs. Shut-Down

i3, i5, and i7; Dual, Quad, Hexa Core Processors. How to they Differ?

Intel's Ivy Bridge Processor: new Features

Submit Your Tip
Submit your computer tip to us; receive full credit for all published tips

Windows Guides on Facebook