Page 1 of 1

if there is more then 1 file then delete old files

Posted: 15 Dec 2011 01:55
by DenotsNiaga
i run a backup to a share and i need to delete old backup's
otherwise my share will run out of disk space

now i run this in file in Scheduled Tasks

@ECHO OFF
IF "%DAY%" == "Monday" GOTO FIRST

:SECOND
forfiles /p d:\bacup /s /m *.* /d -2 /c "cmd /c del @file : date >= 1 day > NUL"
GOTO END

:FIRST
forfiles /p d:\backup /s /m *.* /d -4 /c "cmd /c del @file : date >= 3 days > NUL"
GOTO END

:END

wich works fine, but i need to keep at least 1 file.
so if my backup fails for 2 days, this file will delete my last good backup.

i need to add that i will always keep the last file in this directory.

so something like, if there is only one file then DONT delete anything.

thanks

Re: if there is more then 1 file then delete old files

Posted: 15 Dec 2011 10:36
by aGerman
Someting like that?

Code: Select all

dir /a-d /b /s "d:\bacup\*" >nul 2>&1 ||goto :eof

Regards
aGerman

Re: if there is more then 1 file then delete old files

Posted: 16 Dec 2011 04:27
by DenotsNiaga
thanks for the response but it still deletes all older files when there is only one file in there

now i have this
dunno if i do this correct

dir /a-d /b /s "d:\bacup\*" >nul 2>&1 ||goto :eof

@ECHO OFF
IF "%DAY%" == "Monday" GOTO FIRST

:SECOND
forfiles /p d:\bacup /s /m *.* /d -2 /c "cmd /c del @file : date >= 1 day > NUL"
GOTO END

:FIRST
forfiles /p d:\backup /s /m *.* /d -4 /c "cmd /c del @file : date >= 3 days > NUL"
GOTO END

:END