# Batch file to delete folders by the first 3 letters of name



## mrast (Oct 26, 2012)

Hello,

Im trying to write a batch file that will delete some folders every night before my backup runs.

I have 7 folders called IMGxxxxxx - the xxxxx are repalced by random numbers.

There are other folders on the drive that cannot be deleted so i cant just blat the drive every night.

So id like my batch file to scour the drive and delete any folder starting in IMG.

The drive letter is question is E:\
The machine in question is a Server 2008 installation

Can anybody help me please?

Thankyou in advance


----------



## foxidrive (Oct 20, 2012)

Try this - remove the echo to enable the RD command.


```
@echo off
for /f "delims=" %%a in ('dir E:\IMG*.* /ad /b /s') do echo rd /q /s "%%a"
```
Just an added comment - do you only have one backup copy? It's a good policy to have two or three and rotate them.


----------



## mrast (Oct 26, 2012)

works a treat!! Thankyou.

Yes i backup nightly to RDX drives. However the crappy software does not remove old data prperly even though its told to so each week i have to go in and manually delete the IMG folders or it just fills the RDX drives up and the backup fails.

Spoken a million times with Symantec tech support and get nowhere every time, so given up and will just use a dirty batch file to do what Backup Exec cant!

Thanks


----------



## Donald_Eady (Oct 29, 2012)

What version of Backup exec are you running. Please note that deleting the IMG files from windows and not within backup exec will create orphaned entries withing the Bedb. Please provide me with the version of B.E. that youre using


----------



## mrast (Oct 26, 2012)

Donald - 2010r3.


----------



## Donald_Eady (Oct 29, 2012)

mrast, 

As im sure that you are aware B.E. uses these IMG files to perform your GRT restores, if manually deleted we can not guarantee that B.E. will be able to restore the lost or missing data as the IMG will no longer be present for it to pull the data from. 2010 should look for the oldest IMG prior to writing the new IMG to the storage location and provided that it has reached its expiration it should delete it prior to writing the new. A problem occurs if it is unable to find it and delete it "ex. if it has been manually deleted from the folder" it will continue on and write the next IMG. on the next backup it again attempts to find the missing file and is again unable to. You may be better served by adjusting the protection period for the backup set


----------



## mrast (Oct 26, 2012)

Hi Donald,

I have my media overwrite protection set to 12 hours for my media set and jobs.

I run 3 different jobs every night at 9pm which is my docs and exchange backup, at 1 am which is my sql backups and at 5.30am which is my hyperv machines backup.

So plenty of time for media to expire.

Symantec also made a registry key change and that made no difference.

I run the same 3 jobs, as a full backup mon-fri onto a different rdx drive every night.

Monday will write IMG000000, IMG000001, IMG000002.

Tuesday will write 3,4,5
wednesday will write 6,7,8
Thursday 9,10,11
Friday 12,13,14

The following Monday it does 15,16,17 

Nothing gets deleted.

If i look in the media section the only IMG folders that show are the ones from the days backup before.

Nothing i have tried deleted the damn things.

Surely just doing a catalog on the media will allow me to restore the GRT content?

An i missing something Donald?


----------



## Donald_Eady (Oct 29, 2012)

Mrast,

You are correct in that you will be able to catalog the tapes and restore data after staging the databases back to disk. There will still be corruption within the bedb as the bkf files will still be pionting to IMG locations that no longer exist, but if your planning on cataloging and staging tapes prior to your restore this shouldnt be an issue for you. Out of curiosity in the setup of your backup job under destination and device and media do you have the job set to append or overwrite data by default it is set to append but should be set to overwrite


----------

