cd c:\temp
for /f %i in ('dir /a:d /s /b A*') do rd /s /q %i
Use this to test though:
for /f %i in ('dir /a:d /s /b A*') do echo rd /s /q %i
This will pipe out the commands to be run into the command prompt and allows you to see what's going on.
Bear in mind that this will also search subfolders such as "C:\temp\jjj\aaa" and would delete the aaa folder. If you want it to just look at top level folders "C:\temp\aaa", then remove the "/s"
from the command.
The key to this is the A*, where you would put in your search string. This will accept wildcards such as aaa*
, aaa*
and *aaa*
if you want it to.
Edit: Please note the comment below from @Friedrich 'Fred' Clausen, which is utterly important, otherwise you may end up deleting whole unwanted directories:
If this is running from within a batch file (which is tagged by
this question) you need to use the two percent signs:
for /f %%i in ('dir /a:d /s /b A*') do rd /s /q %%i