Folder deletion command/script

Man of Honour
Joined
20 Sep 2006
Posts
35,994
I need to use a script to delete the following:

e:\logs\logs1\
e:\logs\logs2\

I need to delete all files and folders within those two directories while leaving the original folders intact.

del *.* /Q /S leaves the subfolders
rd e:\logs\logs1\ /S deletes what I want but also deletes the logs1 directory. I need it to stay behind.

If this was Unix I'd have no problem.

OS is W2K3. It needs to be command line base and I can't install any 3rd party apps.

Help please. :)
 
Last edited:
Del "Folder\*" /Q

Should work, You just need to add the wildcard (The asterisk) which will delete everything inside the folder.

Code:
Del "e:\logs\logs1\*" /q
del "e:\logs\logs2\*" /q
 
This should work, may need to tinker with it though :)

FOR /F "tokens=*" %G IN ('dir e:\logs\logs1 /b') DO rd "e:\logs\logs1\%G\" /S /Q
FOR /F "tokens=*" %G IN ('dir e:\logs\logs2 /b') DO rd "e:\logs\logs2\%G\" /S /Q
Del "e:\logs\logs1\*" /q
del "e:\logs\logs2\*" /q

You could probably do it a bit more elegantly with the find command but its to late for that!
 
Back
Top Bottom