Showing results for 
Search instead for 
Did you mean: 

Cannot delete the IMG files

Level 4

I have in the past used a script from these forums to remove IMG files from my backup drive

This has worked really well but on one of my servers it is not doing anything, I run the script from the command line and after a few seconds it comes back to the C: prompt again.

I am running a Windows 2003 SBS server with Backup Exec V11d on it.

Can anyone help?



Employee Accredited Certified
Well as those scripts seem to start by looking for bemcmd in default paths and you may have installed BE anywhere this could cause it to fail.

However you need to be aware that the Backup Exec built in method for removing old IMG folders based on the Overwrite protection settings was enhanced in BE 12.0 and above so really you should be considering upgrading and then using the correct Media Set properties instead of one of these scripts.

What 12.0 and later  does is to try to delete at least one IMG folder every time a set that would use a new IMG folder is started (So a job with 2 Exchange Information Stores in it, would try to erase an overwriteable IMG at the start of the first information store and then erase a second overwriteable IMG at the start of the second information store. The way 11D worked was to try and erase/reclaim an overwriteable IMG folder when the available disk space was reached which 12.x and above will still try and do in addition to the new facility.

One minor comment (for 12.x and newer) you must set your jobs that create IMG folders (Exchange etc) to overwrite at start (not append then overwrite) as we are investigating an issue where the IMG folders appear to not be erased if the job does not start with an overwrite.

Level 4
Hi Colin,

In an ideal world it would be best to upgrade but unfortunately not every company can afford to pay Symantecs rapidly rising prices to keep up to date and so have to manage with what they have got so the work around is really required.

I have now tried two scripts without any success can anyone help at all the scripts are below;

:: Change the following 3 items below to match your installation.
:: * MediaSet - the Backup Exec Media Set Name you're using for backup-to-disk jobs
::   (It's best to make this a name without spaces)
:: * B2Dfolder - the full path to the backup-to-disk folder you're using for the job
:: * BEPath - the full path to the Backup Exec executables (specifically, bemcmd.exe).
::   (If you didn't change it, this is C:\Program Files\Symantec\Backup Exec\becmd.exe,
::   on US English systems)
 SET MediaSet=B2D
 SET B2Dfolder=F:\
 SET BEPath="C:\Program Files\Symantec\Backup Exec\bemcmd.exe"
 SET Action=ECHO
 SET ActionDir=ECHO
 IF /I "%1" EQU "/run" SET Action=DEL & SET ActionDir=RD
 IF /I "%1" EQU "-run" SET Action=DEL & SET ActionDir=RD

:: First, some general cleanup to be sure we're starting fresh
 IF BEPath=="" Echo "Cannot find the path to BackupExec!  Please edit the command script." & goto End
 IF EXIST %B2Dfolder%Media.txt DEL %B2Dfolder%Media.txt
 IF EXIST %B2Dfolder%Media1.txt DEL %B2Dfolder%Media1.txt
 IF EXIST %B2Dfolder%Media2.txt DEL %B2Dfolder%Media2.txt
 IF EXIST %B2Dfolder%Dir.txt DEL %B2Dfolder%Dir.txt
 IF EXIST %B2Dfolder%%Del%.txt DEL %B2Dfolder%Del.txt
:: You may need to stop the winmgmt service, because at least in some environments, it keeps
:: handles open to files we may be planning to delete.  If necessary, uncomment the following
:: (remove the initial "::" from the line).
:: **** Also uncomment it below (in the CLEANUP section) ***
:: NET STOP winmgmt
:: Now we're ready to delete old files (as long as /run was specified,
:: otherwise we'll just display a list)
:: First, dump a list of all the media labels Backup Exec is currently using.  If we can't get this,
:: quit with an error.
  %BEPath% -o132 -j%MediaSet% >%B2Dfolder%Media1.txt
  IF NOT Errorlevel=1 net send %computername% Error getting listing of Backup Exec B2D Media! & GOTO Cleanup
:: Next, extract all the lines showing an actual in-use media (these will be the backup-to-disk file names)
 FINDSTR /c:"LABEL: "  %B2Dfolder%Media1.txt > %B2Dfolder%Media2.txt
 FOR /f "tokens=3 delims= " %%m in (%B2Dfolder%Media2.txt) do ECHO %%m >>%B2Dfolder%%Media.txt
:: Next, list all the files and folders in the Backup-to-Disk directory.
 FOR %%d in (%B2Dfolder%*.bkf) do ECHO %%~nd >>%B2Dfolder%Dir.txt
 FOR /d %%d in (%B2Dfolder%*.) do ECHO %%~nd >>%B2Dfolder%Dir.txt
:: Next, find all lines it the list of files that are NOT (/v) in Backup Exec's
:: list of current media.  This gives us a list of files to be deleted.
 FINDSTR /v /g:%B2Dfolder%Media.txt %B2Dfolder%Dir.txt > %B2Dfolder%Del.txt
:: Finally, execute the required action against each item listed in our Del.txt file
:: from the previous step.  Note again that unless you run this script with the /run
:: command-line parameter, it will not delete files but instead just list them.
 CD /D %B2Dfolder%
 FOR /F %%i in ('findstr /b IMG %B2Dfolder%Del.txt') do %ActionDir% /s/q %%i
 FOR /F %%b in ('findstr /b B2D %B2Dfolder%Del.txt') do %Action% /f/q %%b.bkf
:: Clean up after ourselves, like good citizens!
 :: NET START winmgmt
 IF EXIST %B2Dfolder%Media.txt DEL %B2Dfolder%Media.txt
 IF EXIST %B2Dfolder%Media1.txt DEL %B2Dfolder%Media1.txt
 IF EXIST %B2Dfolder%Media2.txt DEL %B2Dfolder%Media2.txt
 IF EXIST %B2Dfolder%Dir.txt DEL %B2Dfolder%Dir.txt
 IF EXIST %B2Dfolder%Del.txt DEL %B2Dfolder%Del.txt
:END@Echo Off
:: A script to delete BKF files and IMG folders no longer needed by Backup Exec.
:: Original by Armin Kerl, modifications by Matthew Miller.
:: If you have comments or questions, please join the forum and post on the thread at:
:: Note that this will run properly only on a machine running Windows 2003 or XP SP2 with
:: command extensions turned on (which is the default on those systems).
:: History
:: 2008-08-19 AK Original Version
:: 2008-12-31 MM Modified to English, added formatting & comments.
::               Changed to run test only unless /run parameter is specified.
::               Added recursion through B2D subdirectories (since Backup Exec
::               adds \Veritas\B2D to all removable B2D directories on our systems)

2, The second one is a ruby script so I have downloaded and installed ruby as well

img_dir = ARGV[0]
if ARGV.length > 1 then
 testing = true
 testing = false
puts "Deleting from #{img_dir} #{testing}"
curw_dir = Dir.pwd
d =
d.each do |name|
  if File.file?(name)
    if name =~ /img000[0-9]*/
   if testing
    puts "Would delete #{name}"
       puts "Deleted #{name}"
   "Skipping file #{name}"