Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
FOR /F %%A IN (somefile) DO command
FOR /F %%A IN ("somestring") DO command
FOR /F %%A IN(aCommand) DO command
FOR /F "delims=[char/s]" %%A IN (somestring or somefile or aCommand) DO command
FOR /L %%A IN (x y z) DO command
FOR /R [path] %%A IN (set) DO command
FOR /D IN (set) DO command
FOR %%A IN (set) DO command
I believe the bushes in my yard will BURN before God picks up a PC to send a message
FOR /F "tokens=1-3* delims=," %%A in ("cat,dog,horse,the whole zoo") do ( echo token 1: %%A echo token 2: %%B echo token 3: %%C echo the rest: %%D )
token 1: cat token 2: dog token 3: horsethe rest: the whole zoo
FOR /R "C:\MyFolder" %%A in (*.mp3) do ( echo %%A )
for %%A in (*.bat) do ( copy "%%A" D:\NewFolder )
PS. Can FORs be nested?
FOR /F "tokens=1,3 delims=," %%A IN ("cat,dog,horse,the rest") DO( ECHO %%A ECHO %%B
cathorse
QuotePS. Can FORs be nested? Yes, but you cannot have more than a certain number of variables active. FOR /? help says max is 52 (A-Z, a-z) but in fact you can use 1-9 and a few other characters as well. I think it is 63 or 64 but beyond 52 is undocumented.
can't write 8 ) use different symbol like 8: or 8] or 8.
Can FORs be nested?
@echo offfor /f "tokens=1-3 delims=:" %%A in ("big:red:wet") do ( for /f "tokens=1-3 delims=," %%D in ("cat,dog,cow") do ( for /f "tokens=1-3 delims=-" %%G in ("hot-hit-hat") do ( echo %%A %%D %%G echo %%A %%E %%G echo %%A %%F %%G echo %%B %%D %%G echo %%B %%E %%G echo %%B %%F %%G echo %%C %%D %%G echo %%C %%E %%G echo %%C %%F %%G echo %%A %%D %%H echo %%A %%E %%H echo %%A %%F %%H echo %%B %%D %%H echo %%B %%E %%H echo %%B %%F %%H echo %%C %%D %%H echo %%C %%E %%H echo %%C %%F %%H echo %%A %%D %%I echo %%A %%E %%I echo %%A %%F %%I echo %%B %%D %%I echo %%B %%E %%I echo %%B %%F %%I echo %%C %%D %%I echo %%C %%E %%I echo %%C %%F %%I ) ) )
big cat hotbig dog hotbig cow hotred cat hotred dog hotred cow hotwet cat hotwet dog hotwet cow hotbig cat hitbig dog hitbig cow hitred cat hitred dog hitred cow hitwet cat hitwet dog hitwet cow hitbig cat hatbig dog hatbig cow hatred cat hatred dog hatred cow hatwet cat hatwet dog hatwet cow hat
For number 4): [for other people searching]if I saidFOR /F "tokens=1,3 delims=," %%A IN ("cat,dog,horse,the rest") DO( ECHO %%A ECHO %%BOutput is:cathorse
Weeeell, that loop didn't have a bug .No, the answer is cat and horse. Notice that the tokens are 1 AND 3 not 1 TO 3.T-E
I should clean my spectacles!
Of course. I'm just saying that it is a little complex to understand at first. Just a side thought.
There may be up to 25 more IMPLICIT tokens in one FOR structure. (Because there are 26 letters of the alphabet)
@echo offclssetlocalset data= Able Baker Charliefor /f "tokens=1-3" %%: in ("%data%") do ( echo %%: %%; %%^< echo. echo %%^< %%; %%: echo. echo %%: %%^< %%;)
Although not documented by MS, 31 tokens can be used and a total in excess of 65 may be open at any time.
FOR /? help says max is 52 (A-Z, a-z) but in fact you can use 1-9 and a few other characters as well. I think it is 63 or 64 but beyond 52 is undocumented.
can't write 8 )