# Batch script to delete folders with numeric names



## virus2 (Jun 26, 2008)

Friends,I need help deleting folders(not files) from a directory with names as numeric.I have a folder which contains many sub-folders with names as 2357125,4529712,4589712....etc(want to delete all such folders).Apart from these,there are other folders with names as 'Deployment','logs',....etc.(these will remain intact).The numeric folders have PURE numeric names,there is no single alphabet in their name.
Input to script will be the folderpath where these folders are stored.
Pls someone help me out with this..:ermm:


----------



## Squashman (Apr 14, 2005)

Are the folder names always 7 digits?
Do you have any mixed alpha numeric folder names and do any of them begin with a number?


----------



## Squashman (Apr 14, 2005)

Easier than I thought now that I had time to think about it.

```
for /f "tokens=* delims=" %%G in ('dir /ad /b ^|findstr /r /c:"^[0-9][0-9]*$"') do echo %%G
```


----------



## virus2 (Jun 26, 2008)

Squashman said:


> Easier than I thought now that I had time to think about it.
> 
> ```
> for /f "tokens=* delims=" %%G in ('dir /ad /b ^|findstr /r /c:"^[0-9][0-9]*$"') do echo %%G
> ```


thanks a lot for the help.BTW,can you refer some good tutorials on web to refer to learn batch scripting.:smile:


----------



## Squashman (Apr 14, 2005)

Http://www.Dostips.com
http://www.allenware.com/icsw/icswidx.htm


----------



## virus2 (Jun 26, 2008)

Squashman said:


> Http://www.Dostips.com
> MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference


thanks a lot frnd..


----------



## Squashman (Apr 14, 2005)

I hope you realized that you needed to change that ECHO command to the remove directory command. RMDIR %%G
I forgot to change it after doing my testing.


----------

