문제

firts of all im beginner. i have multiple file in directory which its name contain date, i need to find which file is the latest one(just need the date). this is what i have so far

set currentYear=2013
set logDate=0
set tempLogDate=0
set fileName2=0
setlocal enabledelayedexpansion

for /f "delims=" %%a in ('dir /a-d/b/s "%logDirectory2%"^|findstr /riv "^.*\\[^\\]*%now%[^\\]*$"') do (
set fileName2=%%a
call set fileName2=!fileName2!:!currentYear!=%%
set tempLogDate=%currentYear%!fileName2:~0,4!
if !tempLogDate! GTR %logDate% ( set logDate=%tempLogDate% )
)

echo !logDate!

the problem is variable inside loop didnt get change, thanks in advance

*i change some code but still didnt solve... :( what a horrible weeks start

도움이 되었습니까?

해결책

In order to access the valeue of a variable as it is changed within a loop, you need to have enabledelayedexpansion invoked (which you have) AND you then need to use !varname! to access the changing value; `%varname% accesses the PARSE-TIME value, that is, the inital variable value BEFORE the loop was STARTED

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top