tags:

views:

1136

answers:

3

I have a folder "FolderA" which contains three sub-folders: foldera1 foldera2 and foldera3

I need to write a batch file which resides inside "FolderA". It should delete all the folders under "FolderA" as a cleanup activity. I don't know the folder names. rmdir does not support wild cards.

Could someone provide a solution for this small problem?

+4  A: 

something like :

for /f %%a in ('dir /ad /b') do (rmdir /S /Q "%%a")
for /d %%a in (*) do (rmdir /S /Q "%%a")

should do the trick. The second form allow some wildcard selection for directories.

To test it outside a script, in a plain DOS session:

for /f %a in ('dir /ad /b') do (rmdir /S /Q "%a")
for /d %a in (*) do (rmdir /S /Q "%a")

Note the double quotes, in order to be able to delete directories with spaces in them.

VonC
+2  A: 

From command line:

for /D %a in (*) do rd /S /Q %a

In batch/cmd file:

for /D %%a in (*) do rd /S /Q %%a
Arvo
A: 

When you are inside FolderA, run "rmdir /s /q ."

This shows an error on command line of "file in use..."
Yet, it deletes the directory inside it.

shahkalpesh