Ok, I am trying to write a batch file that will make a MS Word document, and I have 99% completed, the document is a list of tracks in a directory, and serves as a label for a CD, my only problem, is that I have a FOR IN DO loop, in which the file name of each track, minus the extension is written to the file, works perfectly, however, I also have an iterator variable in the loop that I += each time to increment, this allows the track number to be written to the file, here is an example of the code I am trying to write, and the problem with it is that when I access the index variable, it writes the pre FOR loop value, not the new += value that is assigned in the FOR loop, any suggestion?!?
::Sample code
SET index=0
FOR %%i IN ("C:\<directory>\*.mp3) DO (
SET /A index += 1
ECHO %index%. %%~ni >> <docFileName>.doc
)
ECHO %index%
EXIT
This code works fine it outputs each new %%~ni with no problems, however, when %index% is accessed each time, the value 0 is always written
When the %index% is accessed the last time by the ECHO line, outside the FOR loop, the proper value is outputed, is there anything I need to do to "update" let say, the index variable value within the for loop so that the proper new value will be outputed?