I'm trying to create a batch file that generates a custom AVIsynth script per each file. Right now the batch file is set to execute from within the folder where the video files exist. What I need to do is get the creation time of the file to generate a timecode burn in. I have no problem getting the info I need. However, if the file was created in the afternoon I need it to be in 24hr time. For example, 2pm needs to display as 14. 

I have a working if statement that creates a `newth` variable that adds 12 if need be. However, if it doesn't need it the variable persists. On each subsequent iteration of the loop the variable doesn't change.

My example. I have two files the first was created at 2pm the other at 12pm. The 2pm file is read first and the `newth` variable becomes 14. So far so good. On the next file the `newth` variable should become 12 but instead remains 14. How do I fix this?

```
@Echo Off & CLS
SetLocal EnableDelayedExpansion
For /F %%a In ('dir *.mpg /b') Do (
    ECHO Processing "%%a"
    echo %%~ta
    set time=%%~ta
    set th=!time:~11,2!
    set tm=!time:~14,2!
    set era=!time:~17,2!
    echo !era!
    if "!era!"=="PM" (
        if !th! LSS 12 ( set /a newth=!th!+12 )
    ) else ( set /a newth=!th!)

    echo !newth!
    echo //AviSynth Test Script >scripts/%%a.avs
    echo DirectshowSource^("%%~fa"^)>>scripts/%%a.avs
    echo LanczosResize^(720,400^) >>scripts/%%a.avs
    echo ShowSMPTE^(^) >>scripts/%%a.avs

    ECHO Back to Console
    Pause
)

```

It's a little messy because I've been using `echo` for debugging. But hopefully the problem is clear.