Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unknown folder delete within a directory using .BAT files

Tags:

batch-file

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?

like image 245
sundar venugopal Avatar asked Nov 17 '08 22:11

sundar venugopal


People also ask

Can a batch file delete files?

Batch file does delete files.

What is the command use to delete a directory with sub directories and?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r .


1 Answers

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.

like image 105
VonC Avatar answered Oct 02 '22 21:10

VonC