Set Ruby variable if it is not already defined. Ask Question 35. In Ruby, how do you set a variable to a certain value if it is not already defined, and leave the current value if it is already defined? Ruby variables set. Don't recommend doing this with local variables though. Edit: In fact v=v is not needed. Share| improve this.
I try to create a batch file to run under Windos XP in a command window (or just double clicking the BAT file). The intention is to take all files with a given extension, concatenate them and add some extra information 'between the files'. To do this, I need to add a counter value like 1 for the first file, 2 for the second and so on. I have managed to solve all other problems to output what I need but the counter variable is not updated as long as I'm inside the FOR loop. See the attached code example.
![Batch File Local Variables In Ruby Batch File Local Variables In Ruby](/uploads/1/2/5/5/125512481/359825033.jpg)
![Files Files](/uploads/1/2/5/5/125512481/289755245.png)
Put it in a BAT file and run it to see the problem. The last echo after the FOR loop gives the correct value. Any hints are much appreciated. @echo off set /A Counter=1 echo Initial value of Counter:%Counter% echo. For%%f in (.) do ( echo File found:%%f echo Counter Before increment:%Counter% set /A Counter+=1 echo Counter After Increment:%Counter% echo. ) echo Counter after for loop:%Counter% Select all.