I have the following situation. I got a Temp folder which gets filled with all kinds of files and directories. I want/need to clean it regularly, but I can't figure out a command or set of MS-DOS command to do so. Command called erase deletes all the files, so no problem there, but the directories is the thing I'm struggling with. I know some of you might suggest deleting the Temp directory and then creating it, which is NOT an option for me unfortunately, since I MUST keep it intact, since doing messes up things on my system.

Any ideas, good people? :)


In a MS-DOS system use deltree.

DELTREE [/Y] directory\*.*

From a cmd windows in the latest versions you can use rd.exe or rmdir.exe

rd directory/* /s


rmdir directory/* /s

  • 1
    Well, DELTREE is out of the question, since we're talking command promt in Winodws 8 basically. As for rd and rmdir, for some reason none of them does what I need. I mean, if I do rm/rmdir c:\q* /s it 1) asks for a confirmation, which it should not because of /s 2) does nothing when I confirm it. Weird... Any other ideas, good people of SuperUser :) – adamas Feb 1 '13 at 12:16

If you don't want to have it asking you for confirmation you need also the /Q switch

I have a batch file that does the following:

rmdir E:\Documents /s /q

I wanted it to delete the contents of the Documents folder but instead this command deletes the whole folder. I tried E:\Documents* but to no avail.

So what I ended up doing was:

rmdir E:\Documents\*.* /s /q
mkdir E:\Documents
@del /S /Q /F temp\* >nul
@for /d %%i in (temp\*) do @rmdir /s /q "%%i"
  • While this may answer the question, it would be a better answer if you could provide some explanation why it does so. – DavidPostill Mar 14 '16 at 21:45

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.