Click to See Complete Forum and Search --> : xcopy - timestamp (how to compute Yesterday)


THY02K
August 28th, 2007, 08:56 PM
Hey know how to do this? It's a MS DOS batch file, I'm having trouble computing "Yesterday" and xcopy /D date command - I want all files updated since yesterday.

SET YESTERDAY= %DATE% -1 ----- how do I compute *yesterday*?
SET USERNAME=someguy
xcopy %LOGFILEDIR% %SHAREDIR%\%YESTERDAY%\%USERNAME% /e /I /C /K /D:%YESTERDAY%


Bolded part is where the problem is ... Also /D switch takes the following format:

/D:8-29-2007

Reference: xcopy (http://www.computerhope.com/xcopyhlp.htm)

THY02K
August 28th, 2007, 09:55 PM
for /f "tokens=2" %%g in ('date /t') do set datesplit=%%g

set mm=%datesplit:~0,2%
set dd=%datesplit:~3,2%
set yyyy=%datesplit:~6,4%

echo %mm%
echo %dd%
echo %yyyy%

set /A dd=%dd% - 1
set /A mm=%mm% + 0

if /I %dd% GTR 0 goto FINISH
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUST
set /A mm=12
set /A yyyy=%yyyy% - 1

:ADJUST
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
if %mm%==12 goto SET31
goto ERROR

:SET31
set /A dd=31 + %dd%
goto FINISH

:SET30
set /A dd=30 + %dd%
goto FINISH

:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29

:SET28
set /A dd=28 + %dd%
goto FINISH

:SET29
set /A dd=29 + %dd%

:FINISH
if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%

rem here you can format how you like, from above it should be
set YESTERDAY=%mm%-%dd%-%yyyy%
echo %YESTERDAY%

PeejAvery
August 29th, 2007, 07:55 AM
So is this solved? You posted code in a second post without any explanation.

THY02K
August 29th, 2007, 11:40 AM
yes thanks but only partly

I browsed source forge, didn't find one as many feature as "PA Server Monitor Pro" - which cost US$99 bucks...

That's a pretty good price for what it has to offer. But its log file monitor dont let you to say, monitor latest/most recently updated/created file in the specified directory. But with combination of shell script and "OA Server Monitor Pro" I get requirements met.