# Batch file for deleting files starting with IMG******



## Adam2012 (Apr 25, 2012)

Hi all, 

I am looking for some help creating a batch file to delete files starting with IMG******. They are always 6 randonmly genorated numbers after the IMG part. For example, they will be IMG000004, IMG000041 and IMG123500. 

I have a removeable disk on E:\ that is set to have a daily backup backup to it, however, the software doesnt overwrite the IMG files correctly meaning the drive fills up and my backup fails.

So, how can I create a batch file that finds all of the folders starting with IMG and then deletes them from E:\

Thanks very much

Adam


----------



## Squashman (Apr 4, 2003)

You are contradicting yourself. First you said delete files starting with IMG and then you said delete folders staring with IMG?

If they are folders are these folders all in the Root of the E:\ drive?
E:\IMG000004
E:\IMG000041


----------



## Adam2012 (Apr 25, 2012)

I meant folders not files. Yes, they are on the root so will be like:
E:\IMG000004 (Folder)
E:\IMG000041 (Folder)

Any help?


----------



## Squashman (Apr 4, 2003)

```
pushd E:\
for /D %%G in (IMG*) do rd /s /q "%%G"
popd
```


----------

