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?
Batch file does delete files.
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With