deleting old backups

Microsoft Windows xp professional editio...
September 11, 2009 at 13:20:41
Specs: Windows XP
This is from an old post of a batch file provided by M2.

deleting old backups

http://www.computing.net/answers/pr...

##sample script##

:: keep14z2.bat
@echo off
pushd "C:\Program Files\Microsoft SQL Server\MSSQL$SIMS\BACKUP"

:loop

dir /b/od *.zip > %TEMP%\templist
set /p file2del=<%TEMP%\templist
call :deleter %file2del%
popd
goto :eof

:deleter

dir /a-d *.zip |find "File(s)">%TEMP%\#
for /f "tokens=1" %%T in (%TEMP%\#) do if %%T LEQ 14 goto :eof
del %1
goto :loop

:eof
:: DONE

The script executes perfectly and deletes all but the last 14 *.zip files.

But I tested the script when there are no (zero) (none) *.zip in the specified directory, then the script just loops endlessly.

For some reason this script does not consider 0 LEQ 14 and does not goto :eof

Does this make sense? M2 are you still out there? Anyone? Ideas?

Thank you.

Surfred


See More: deleting old backups

Report •


#1
September 11, 2009 at 13:45:05
Change this:
dir /a-d *.zip |find "File(s)">%TEMP%\#

To this:
dir /a-d *.zip |find "File(s)">%TEMP%\# || goto :eof


Report •

#2
September 14, 2009 at 06:03:14
problem resolved. thanks for the help.

Report •

Related Solutions


Ask Question