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
batch reinitialize global variable inside loop and use it outside loop
-
02-06-2022 - |
سؤال
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
المحلول
لا تنتمي إلى StackOverflow