0
votes

I've been working on a batch script to check filedates. I had it working yesterday morning, but for some reason, the variables that I set have started to be non-functional. Here is the code:

for /f %%a in ('dir /B/A:D') do (
    for /f "tokens=1-3 delims=/ " %%b in ("%%~ta") do (
        set FCMONTH=%%b
        set FCDAY=%%c
        set FCYEAR=%%d
        echo %FCMONTH%\%FCDAY%\%FCYEAR%
    )
)

Line-by-line:

  1. Find folders in the working directory
  2. Parse the file creation date into the first three tokens, assigned to %b, %c, and %d
  3. (through 5) Assign variables to the tokens
  4. (actually 6) Print out the result (debug I included that hasn't given me any new info)

When looking at the script results in cmd.exe, FCMONTH/DAY/YEAR are all being set correctly, but the echo is failing to read them:

results

Does anyone have any insights to my problem? I don't understand why it's failing to work all of a sudden.

Thanks

1

1 Answers

2
votes
setlocal enableDelayedExpansion
for /f %%a in ('dir /B/A:D') do (
    for /f "tokens=1-3 delims=/ " %%b in ("%%~ta") do (
        set FCMONTH=%%b
        set FCDAY=%%c
        set FCYEAR=%%d
        echo !FCMONTH!\!FCDAY!\!FCYEAR!
    )
)

Delayed expansion