1.

Solve : Simple for loop question?

Answer»

Hey all.  This one seems like it should be simple...  I have a SCRIPT containing

for %%x in (*.sql) do (
echo Working on file - %%x...
)

echo.

for %%X in (myDll1.dll myDll2.dll myDll3.dll) do (
echo Working on file - %%x...
)

set COM_LIST=(myDll1.dll myDll2.dll myDll3.dll)

echo.

for %%X in %COM_LIST% do (
echo Working on file - %%x...
)

==================================

This results in:

Working on file - mySql1.sql...
Working on file - mySql2.sql...

Working on file - %x...
Working on file - %x...
Working on file - %x...

Working on file - %x...
Working on file - %x...
Working on file - %x...

=================================

The first set of echo statements are correct but what is up with the second two?  I KNOW I have to be missing something simple but I am in a hurry and don't have time to run around in circles with this.

Thanks!
You are using %%X and %%x as For variables.   Yea, I just caught that right before you posted.  Thanks for your REPLY though...  Gotta watch the copy/paste stuff I guess...In FOR loops, the variable name is case sensitive, that is %%A to %%Z are not the same as %%a to %%z, so in your code the FOR variable is %%X but in the loop you are referencing %%x
Hey, thanks, Salmon Trout...  It was a simple oversight on my part and in my haste I PROBABLY posted that question prematurely.  I appreciate your INPUT, though. Quote

for %%X in %COM_LIST% do (
echo Working on file - %%x...
)

Also that should probably be

for %%X in (%COM_LIST%) do (
echo Working on file - %%X...
)


Discussion

No Comment Found