@echo off
setlocal EnableExtensions EnableDelayedExpansion
REM Define source and destination locations, and file patterns to copy
set SourceDir=c:\temp\EE26352923\source
set DestDir=c:\temp\EE26352923\dest
set MatchExts=*.trn *.bak
REM Get todays date and convert to Julian
for /F "tokens=2-4 delims=/ " %%A in ("%DATE%") do set TodaysDate=%%C%%A%%B
call :jdate TodaysJDate %TodaysDate%
REM Move to source directory, find all files matching desired pattern
pushd "%SourceDir%"
for %%A in (%MatchExts%) do (
REM Get files modification date, convert to Julian
set FileDate=%%~nA
call :jdate FileJDate !FileDate:~-12,8!
REM Calculate age of file in days, if older than 7 days move to destination
set /A FileAge=%TodaysJDate%-!FileJDate!
if !FileAge! GTR 7 move "%%~A" "%DestDir%"
)
popd
REM Move to destination directory, find all files matching desired pattern
pushd "%DestDir%"
for %%A in (%MatchExts%) do (
REM Get files modification date, convert to Julian
set FileDate=%%~nA
call :jdate FileJDate !FileDate:~-12,8!
REM Calculate age of file in days, if older than 28 days delete from destination
set /A FileAge=%TodaysJDate%-!FileJDate!
if !FileAge! GTR 28 del "%%~fA"
)
popd
exit /b
REM Subroutine to calculate Julian date
:jdate return-variable date-string(YYYYMMDD)
set DateStr=%~2
set yy=%DateStr:~0,4%
set /A mm=1%DateStr:~4,2%-100
set /A dd=1%DateStr:~6,2%-100
set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
set /a %~1=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
exit /b
|