Windows del command not working?
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
122 Answers
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
2del 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