Delete/Archiver files older than x-days – Cleanup Script

Script to delete files older than x-days. The script is built to be used as a scheduled task, it automatically generates a log file based on the copy location and the current date/time. There are various levels of logging available.

Or use simple Robocopy to archiver Old files tO USB HDD

@echo off
set scriptPath=c:\script
set logPath=c:\script\log
set dateStamp=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%

@REM *** START: Turns logging on ***
if “%~1” == “NOWLOGGING” goto NowLogging
set SchedulesLogFile=%logPath%\%~n0 – %date:/=-% %time::=_%.txt
%0 “NOWLOGGING” > “%SchedulesLogFile%” 2>&1
rem goto :EOF

@REM *** END: Turns logging on ***

@rem Guts of batch file…
echo [%date% %time%] starting…
echo *** start of actual batch file…

@REM Clean old BAK
rem del /q  Z:\Archiver\Data\*.BAK

@REM Move files older than 60 days to USB hdd for archiver
robocopy D:\Data Z:\Archiver\Data /MOV /MINAGE:60 /E /COPY:DAT /NDL /NP /R:3 /W:3

@rem add Otiont [/L] to make a run test only

echo *** end of  batch file…
echo [%date% %time%] ending…