Batch file with for loops isn't working
Posted: 07 Aug 2014 12:57
I'm trying to make a script that takes all the .sql files in a folder and counts the amount of "/*" and "*/" as a first token. I have the following script:
It correctly goes through all the files and the %%b also contains the first token (in this cas a string). Now the issues that I have are:
1) When I redirect the %%b to a file then it's for example: "/* " and a new line I suppose. I'm assuming this is why the IF %%b=="*/ " isn't working. Is there somehow to trim the space and the new line?
2) The incrementation does not seem to work. It's like it does not know the end variable. Is this because it is in the outer loop?
3) IF NOT %start%==%end% does not work neither. Why?
Is there anyone who can help me out with this?
Code: Select all
FOR /F "delims=" %%a IN ('DIR /b *.sql') do (
SET start=0
SET end=0
SET correct=1
FOR /F "tokens=1" %%b IN (%%a) do (
IF %%b=="/*" (
SET /A start+=1
)
IF %%b=="*/ " (
SET /A end+=1
)
)
IF NOT %start%==%end% (
ECHO NOK
)
)
It correctly goes through all the files and the %%b also contains the first token (in this cas a string). Now the issues that I have are:
1) When I redirect the %%b to a file then it's for example: "/* " and a new line I suppose. I'm assuming this is why the IF %%b=="*/ " isn't working. Is there somehow to trim the space and the new line?
2) The incrementation does not seem to work. It's like it does not know the end variable. Is this because it is in the outer loop?
3) IF NOT %start%==%end% does not work neither. Why?
Is there anyone who can help me out with this?