10

I need to delete folders in a folder in one shot, and this folders start with a common name, but does not end with. So any command with del/rm to do this? I tried with wildcards but that didn't work.

c:\temp> rmdir hello* --- directories with starting charecters as 'hello', didn't work

c:\temp> rmdir hello*.* --- didn't work

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Srikanth Yadake
  • 533
  • 2
  • 11
  • 25

2 Answers2

9

From the command line:

for /d %i in (hello*) do rd "%i"

In a batch file:

for /d %%i in (hello*) do rd "%%i"
Jcl
  • 27,696
  • 5
  • 61
  • 92
  • thanks it worked, but forgot to mention that the folders are zipped! – Srikanth Yadake May 21 '13 at 09:46
  • If the folders are zipped, then they are not "folders", they are zip files (regardless what the Windows Explorer might show you) and the answer would be completely different. Can you post the result of a `dir` command on the DOS prompt for that folder, so we can see what are you exactly referring to? – Jcl May 21 '13 at 10:50
  • 05/21/2013 02:57 PM 51,223 IncidentReport_20130521_145737177.zip 05/21/2013 02:57 PM 52,639 IncidentReport_20130521_145744153.zip 05/21/2013 02:57 PM 52,714 IncidentReport_20130521_145744953.zip 05/21/2013 02:57 PM 52,793 IncidentReport_20130521_145745734.zip – Srikanth Yadake May 21 '13 at 11:34
  • as u can see the all these zip files have IncidentReport as thr initial charecters. So i need to delete these zip files at once – Srikanth Yadake May 21 '13 at 11:37
  • Then you only need to do `del IncidentReport*.zip`. "Zipped folders" are not really "folders"... they are files. – Jcl May 21 '13 at 13:53
4

Try this - remove the echo if it works the way you expect it.

for /d %%a in (hello*) do echo rd /s /q "%%a"

change all %%a to %a to execute it from the command line.

foxidrive
  • 40,353
  • 10
  • 53
  • 68