Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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
:: DONEThe 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

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

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |