3

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? :)

3

3 Answers 3

10

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

or

rmdir directory/* /s

1
  • 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, 2013 at 12:16
0

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
0
@del /S /Q /F temp\* >nul
@for /d %%i in (temp\*) do @rmdir /s /q "%%i"
1
  • 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, 2016 at 21:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .