I'm trying to delete a large directory. I run the delete (del /f node_modules), and it appears to work, but then the directory is still there... (When I try to delete it from the file explorer, it usually gives me some flavor of "you need admin permissions" or "can't delete because file is in use" or it just takes forever.)

Here's my question: what causes the del command to appear to work, but not actually work? I'd expect some output indicating the directory wasn't deleted.

Picture of the command used, and the result Another example

  • Does Shift+Delete work? Try skipping the Recycle Bin. – Mr Ethernet Aug 3 '19 at 18:30
  • Provide a screenshot of the ACL for the folder in question. If you are getting an error indicating a permission problem it sounds like you don't have the required permissions to delete it. It does not matter if you are an Administrator, if you don't currently have the required permissions, you would get a permission error. Please do not submit a comment in response to this comment. Instead, edit your question with the information required to answer your question. – Ramhound Aug 3 '19 at 18:30
  • There's no error in the output. The command appears to complete. Also thanks for that shift+delete tip, although I need to do this programmatically, as part of a script. – JohnnyBlack Aug 3 '19 at 18:33
  • @JohnnyKumpf - You said in your question there was an error. Please provide the exact error and that screenshot I requested. Your question cannot be answered without this information. – Ramhound Aug 3 '19 at 18:42
  • My goal isn't to delete it from the file explorer. I want to force a delete from the command line. I'm not sure exactly which errors produce what behavior; what I really want to know is what are the possible causes for the behavior I'm observing in the cmd: namely that the del command appears to work, but the directory is still there afterwards. – JohnnyBlack Aug 3 '19 at 18:44

If I didn't have appropriate permissions, the cmd doesn't throw an access denied or something?

That's not how del is designed to work. If files are deleted, then del will inform you. If no files are deleted then del is silent or will display an error message (for example "Access is denied.").

Normally DEL will display a list of the files deleted, if Command Extensions are disabled; it will instead display a list of any files it cannot find.

Source Del - Delete Files - Windows CMD - SS64.com

If no files are deleted and you do not have the appropriate permissions to remove them an error message will be displayed:

F:\test\foo>del C:\Windows\notepad.exe
Access is denied.

I'd expect some output indicating the directory wasn't deleted.

If you use del with a directory name then it will delete the files in the directory. The directory specified is not deleted.

If a folder name is given instead of a file, all files in the folder will be deleted, but the folder itself will not be removed.

Source Del - Delete Files - Windows CMD - SS64.com

To delete both directories and the files and subdirectories use rd (an alias for rmdir):

Remove (or Delete) a Directory.


RD pathname
RD /S pathname
RD /S /Q pathname

/S : Delete all files and subfolders in addition to the folder itself. Use this to remove an entire folder tree.

Source - RD - Remove Directory - Windows CMD - SS64.com

  • Well, del C:\Windows\notepad.exe is definitely not silent here. – user1686 Aug 4 '19 at 7:57
  • @grawity Answer updated – DavidPostill Aug 4 '19 at 8:19

del will delete all contents, but (even with /f or /s) it never removes the directories themselves; that's just how it was written.

Use rmdir /s instead:

rd/s/q node_modules
  • 1
    when I cd into the directory, all the files are still there – JohnnyBlack Aug 3 '19 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.