Delete files and folders using command line
How to delete files and folders using command line?
Delete files: del /q destination\*
Delete subfolders: for /d %x in (destination\*) do @rd /s /q "%x"
So if you want to delete files and subfolders in the destination folder, you can run both commands. For example, my destination folder is
D:\Work\common\download\picstodelete, my commands goes like
C:\WINDOWS\system32>del /q D:\Work\common\download\picstodelete\* C:\WINDOWS\system32>for /d %x in (D:\Work\common\download\picstodelete\*) do @rd /s /q "%x" C:\WINDOWS\system32>
Note: you can both run cmd from Run dialog as usual and run cmd.exe as Administrator, you get the same result, but if the folder you're about to delete requires Administrator authority, you better right-click on cmd.exe and select run as Admin. And the folder /picstodelete/ is not deleted, only everything in it are deleted.
After running the two commands, you can press Windows + D to go back the desktop and you'll find that recycle bin is empty, I mean what you just deleted are not in it. The two commands work the same as Ctrl + A and then Shift + Delete. So there is no difference on deleting files and folders between pressing Shift + Del and commanding? No, imaging you have to delete stuff in that folder on a Server every day, command line method is the best way, because we can put the two commands into a bat file, like a delete.bat file.
The delete.bat file goes like:
del /q destination\* for /d %%x in (destination\*) do @rd /s /q "%%x"
Yes, two "%"s in the bat file. This is from user of Stackoverflow.
As you know, delete does not mean erase, files and folders deleted from command line can still be recovered by certain software, if you mean secure delete and leave no traces to free data recovery program, it is better to erase them permanently in ByebyeData Eraser, in which we have Erase files and folders and more functions to secure data. Of course, if the deletion is all about to free up disk space, the command prompt worth a try.
Related: How to erase files and fodders?