SciFi Posted February 8, 2012 Posted February 8, 2012 Hey, can I do this in dos?Used to do similar on Unix but can't see how to make it work for Windows.-----Set Pets=(Cats Dogs Horses)Set Cats=(FiFi FruFru Fluffy)Set Dogs=(Lassie MrMuggles RinTinTin)Set Horsese=(MrEd Trigger)FOR %%A in %Pets% DO ( FOR %%B in %%A DO ( Echo “%%A %%B” ))-----Output should be…Cats FiFiCats FruFruCats FluffyDogs LassieDogs MrMugglesDogs RinTinTinHorses MrEdHorses TriggerThis obviously does not work, is there any way to achieve this?Simon.
jaclaz Posted February 8, 2012 Posted February 8, 2012 This obviously does not work, is there any way to achieve this?Are you talking of DOS or of a NT system (command.com vs. CMD.EXE)?jaclaz
Scr1ptW1zard Posted February 8, 2012 Posted February 8, 2012 I do not have a DOS system to test this on, only a Windows 7 command prompt (cmd.exe).This will do for the specific conditions you have listed.Changes will need to be made if any of the pet names will have spaces.@echo offSet Pets=Cats Dogs HorsesSet Cats=FiFi FruFru FluffySet Dogs=Lassie MrMuggies RinTinTinSet Horses=MrEd TriggerFor %%a In (%Pets%) Do ( For /f "Tokens=1,* delims== " %%b In ('set %%a') Do ( For %%n In (%%c) Do ( Echo %%a %%n ) ))
jaclaz Posted February 8, 2012 Posted February 8, 2012 If I may, if DELAYEDEXPANSION is set, you don't even need the FOR /F:@ECHO OFFSETLOCAL ENABLEEXTENSIONSSETLOCAL ENABLEDELAYEDEXPANSIONSet Pets=Cats Dogs HorsesSet Cats=FiFi FruFru FluffySet Dogs=Lassie MrMuggles RinTinTinSet Horses=MrEd TriggerFor %%A In (%Pets%) Do ( For %%B In (!%%A!) Do ( For %%C In (%%B) Do ( Echo %%A %%C ) ))jaclaz
gunsmokingman Posted February 8, 2012 Posted February 8, 2012 Here is a way of doing what the poster wants using VBS script. Dim Pets :Pets = Array("Cats","Dogs","Horses") Dim a,c,i,z '-> Loop Threw Pets Array For Each a In Pets c = c + 1 call SortArray(a, c) Next'-> Function To Display Pets Array And Names Function SortArray(Item, N) Select Case N Case 1 :i = Array("FiFi", "FruFru", "Fluffy") Case 2 :i = Array("Lassie", "MrMuggles", "RinTinTin") Case 3 :i = Array("MrEd", "Trigger", "Silver") End Select For Each z In i WScript.Echo Item & vbTab & z Next End FunctionProduces this outputCats FiFiCats FruFruCats FluffyDogs LassieDogs MrMugglesDogs RinTinTinHorses MrEdHorses TriggerHorses Silver
SciFi Posted February 10, 2012 Author Posted February 10, 2012 Thanks all, I'll run that on all systems (NT, XP, W7) today and see how it goes.Not going to have issues with spaces, naming conventions we use prohibit it.cheers
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now