3

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

paiseha
  • 169
  • 1
  • 3
  • 10

1 Answers1

1

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

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • 1
    thanks for the response, i did play around using your tips,but still the same, i think i need to throughly learn the basic of VARIABLE EXPANSION first before do this, thanks anyway, appreciated it – paiseha Jul 12 '13 at 08:52