Embedding IF inside FOR statement
Posted: 09 May 2016 09:00
Hi, I have the following script that I'm trying to run (this is just a subsection of it where the issue exists). Basically, I receive 4 files -- one for 2016, 2015, 2014 and 2013. The script, in this instances, simply moves that file (for that year) to a folder that corresponds to the date. Rather than coding each one I wanted to loop through them. The script worked perfectly before adding the "FOR" statement so it has to be how I'm using it. Any assist would be greatly appreciated!!
When I reach the IF statement I receive an error which I cannot catch but believe it is referring to the FOR not being closed.
Code: Select all
FOR /L %%A IN (%firstYear%,1,%lastYear%) DO (
SET tFileCur=my_filename%%A.xls
IF EXIST "%foldernm%\!tFileCur!" (
ECHO. Processing: !tFileCur!... found.
SET /a repCount=repCount+1
: move to todays folder
MOVE /Y "%foldernm%\%tFileCur%" "%foldernm%\%fileDate%\"
:
) else (
ECHO. Processing: !tFileCur!... Not found.
SET /a missCount=missCount+1
)
)
When I reach the IF statement I receive an error which I cannot catch but believe it is referring to the FOR not being closed.