Batch nested for loop trouble

November 29, 2010 at 01:54:26
Specs: Windows 7
Quick query, I know exactly what I want to achieve and I feel like i'm only one step away from doing that. Essentially my code is trying to find all the terminal.exe and for each terminal.exe load and pass the variable %b only once.

For example it should basically go if there is three terminal.exe's found and 10 directories found in the folder called 'profiles'

\pa\terminal.exe "55-'pony1'
\mo\terminal.exe "55-'turtle1'
\ma\terminal.exe "55-'horse1'

and then leave it at that.

So far I have this

for /F "tokens=*" %%a in ('dir /b /s terminal.exe') do (for /F "tokens=*" %%b in ('dir /ad /b profiles') do echo "%%a" "55-'%%b'")

Which loads EACH terminal.exe 10 times with that parameter, and then goes on to open the next terminal.exe another 10 times. I assume I need to do something with delayedexpansion but I don't know in this instance.

See More: Batch nested for loop trouble

Report •

November 29, 2010 at 05:02:26
So with 3 exes and 10 profil which ones do you want to pair?

Life is too important to be taken seriously.


Report •

November 29, 2010 at 13:56:30
Both the number of exe's and profiles vary, hence the need to make a list out of them.

With the code I have it loads each exe by the number of profiles, so I end up with 10 instances of the same profile on each exe.

terminal.exe1 profile1
terminal.exe1 profile2
terminal.exe1 profile3
terminal.exe1 profile4

terminal.exe2 profile1
terminal.exe2 profile2
terminal.exe2 profile3
terminal.exe2 profile4

That is not the behaviour I want, I need it to be this.

terminal1.exe1 profile1
terminal1.exe2 profile2
terminal1.exe3 profile3

Does that help explain it?

Report •

November 29, 2010 at 14:59:45
Nope. Same question. Which pairs DO you want?

Life is too important to be taken seriously.


Report •

Related Solutions

November 29, 2010 at 15:09:03
I want it to load them ALL, if that is the question. I don't want/need to single them out. I am trying to load several terminal.exe sequentially each with different paramaters from different folders.

Report •

Ask Question