Computing.Net > Forums > Programming > deleting old backups

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

deleting old backups

Reply to Message Icon

Name: Surfred
Date: September 11, 2009 at 13:20:41 Pacific
OS: Windows XP
Product: Microsoft Windows xp professional edition
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: September 11, 2009 at 13:45:05 Pacific
Reply:

Change this:

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

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


1

Response Number 2
Name: Surfred
Date: September 14, 2009 at 06:03:14 Pacific
Reply:

problem resolved. thanks for the help.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: deleting old backups

deleting old backups www.computing.net/answers/programming/deleting-old-backups/13582.html

Batch to copy and increment folders www.computing.net/answers/programming/batch-to-copy-and-increment-folders/18395.html

Need batch file to delete old files www.computing.net/answers/programming/need-batch-file-to-delete-old-files/14092.html