7

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 03 '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 03 '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 03 '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 03 '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 03 '19 at 18:44
  • Why won't you provide the ACL for the folder? It seems you are avoiding providing that information on purpose. – Ramhound Aug 03 '19 at 18:55
  • For one thing, I'm not totally sure how to get it. Another is I already deleted the directory with shift+delete, so I'm not sure I can. But mostly, I don't care about this particular situation. I just want to know what criteria can lead to the behavior where the del command appears to work and doesn't. Is there something you're going to look for in the control list that causes the del command to look like it completed, when it didn't? If so, just tell me that generally, because again, I don't really care about this specific case. What issue(s) cause(s) this symptom, in general? – JohnnyBlack Aug 03 '19 at 19:00
  • The ACL can be viewed by viewing the properties of the folder. What issue(s) cause(s) this symptom, in general? - By not having the appropriate permissions. – Ramhound Aug 03 '19 at 19:15
  • I'm voting to close this question as off-topic because the author already deleted the folder in question. – Ramhound Aug 03 '19 at 19:16
  • If I didn't have appropriate permissions, the cmd doesn't throw an access denied or something? It just pretends to delete it without doing anything? – JohnnyBlack Aug 03 '19 at 19:18
  • @JohnnyBlack - I recently wrote an answer here https://superuser.com/questions/1462176/two-files-will-not-delete-from-hdd/1462392#1462392 that resolved this sort of problem for someone else. Give that solution a try as it's usually always successful for me assuming the issue doesn't have something to do with the further notable items section. – Vomit IT - Chunky Mess Style Aug 04 '19 at 12:29
  • Thanks for that answer! I'm fairly certain that the "in use" under your further notable items was the culprit. That explains what I was seeing. – JohnnyBlack Aug 22 '19 at 16:11

2 Answers2

7

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

Syntax

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

DavidPostill
  • 156,873
5

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
u1686_grawity
  • 452,512