date - Can anyone explain this curious batch behavior using "%~t1" and give a solution -
can explain following me:
the code:
@echo off setlocal disabledelayedexpansion set pf=c: set url=http://www.rarlab.com/rar set fn=config.sys call :sub1 "%url%" "%fn%" goto :eof :sub1 echo:path=[ %pf%\%~2 ] if exist %pf%\%~2 (call :readdate "%pf%\%~2") & set "_datum1=%_result%" echo:date1=[ %_datum1% ] if exist %pf%\%~2 (call :readdate "%pf%\%~2") & set "_datum2=%_result%" echo:date2=[ %_datum2% ] goto :eof :readdate setlocal %%a in (%~1) set "_tvar=%%~ta" echo:date=[ %_tvar% ] endlocal & set "_result=%_tvar%" exit /b 0 :end
the output:
path=[ c:\config.sys ] date=[ 10.06.2009 23:42 ] date1=[ ] date=[ 10.06.2009 23:42 ] date2=[ 10.06.2009 23:42 ]
so if @ line 3 of output there no date/time - why ????? if it's not big bug of cmd.exe can please me solving problem. need both date/time data comparison.
addendum:
is somehow possible read date/time in first "sub" without using second "readdate" ??
i tried following:
if exist %pf%\%~2 set "_datum1=%pf%\%~t2"
but not work because "~t2" seems work variable holds full path , filename together.
@echo off setlocal disabledelayedexpansion set pf=c: set url=http://www.rarlab.com/rar set fn=config.sys call :sub1 "%url%" "%fn%" goto :eof :sub1 echo:path=[ %pf%\%~2 ] if exist %pf%\%~2 (call :readdate "%pf%\%~2") set "_datum1=%_result%" echo:date1=[ %_datum1% ] if exist %pf%\%~2 (call :readdate "%pf%\%~2") set "_datum2=%_result%" echo:date2=[ %_datum2% ] goto :eof :readdate setlocal %%a in (%~1) set "_tvar=%%~ta" echo:date=[ %_tvar% ] endlocal & set "_result=%_tvar%" exit /b 0 :end