What is the purpose of the for command? I mean... what does the for test? This is the layout for a FOR command:
FOR /F ["Options"] %%Variable IN ('Command') DO Command [Parameters]
But what does it test? What is the %%Variable for? And how do I obtain and use multiple delimiters? THANKS!
For Questions
Moderator: DosItHelp
Re: For Questions
Run this in a folder and see what it does.
Your question is poor - someone would have to teach you every aspect of the for-in-do BY TYPING.
It's better for you to show an example and ask your question relating to it.
Code: Select all
@echo off
for %%a in (*.*) do echo %%a
pause
Your question is poor - someone would have to teach you every aspect of the for-in-do BY TYPING.
It's better for you to show an example and ask your question relating to it.
-
- Posts: 65
- Joined: 08 Jun 2012 07:48
Re: For Questions
Does this help?
FOR /F "tokens=1-5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
What does the %%A represent? Since I see the use of 5 of those parameters here...
And just to confirm, the for loop is used to keep looping in search of the correct variable or file(s)? Thanks again
FOR /F "tokens=1-5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
What does the %%A represent? Since I see the use of 5 of those parameters here...
And just to confirm, the for loop is used to keep looping in search of the correct variable or file(s)? Thanks again
Re: For Questions
john924xps wrote:Does this help?
FOR /F "tokens=1-5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
What does the %%A represent? Since I see the use of 5 of those parameters here...
%%A is a metavariable. When used it contains part of the input line, or all of it, depending on the tokens and delims that are used.
If you have "tokens=1,3" then you will get the first word in %%A and the third word in %%B.
And just to confirm, the for loop is used to keep looping in search of the correct variable or file(s)? Thanks again
It parses multiple lines of text, or a single line of text. Each time the DO command part is executed it is operating on a different line - until it runs out of lines.
-
- Posts: 65
- Joined: 08 Jun 2012 07:48
Re: For Questions
So what you're saying is that I can specify ANY character for the metavariable?
FOR /F "tokens=1-5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
can also be considered as
FOR /F "tokens=1-5 delims=, " %%B IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E ?
And what if I have:
FOR /F "tokens=2,5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
what would happen then?
I'm completely confused by the layout of the command...
FOR /F "tokens=1-5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
can also be considered as
FOR /F "tokens=1-5 delims=, " %%B IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E ?
And what if I have:
FOR /F "tokens=2,5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
what would happen then?
I'm completely confused by the layout of the command...
Re: For Questions
john924xps wrote:So what you're saying is that I can specify ANY character for the metavariable?
You can start with any ascii printable character, including wildcards as some foolish people do, without realising how new people to batch can become confused.
The sequence of metavariables is determined by their ASCII value. %%A is not the same as %%a, also. Case is significant.
FOR /F "tokens=1-5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
can also be considered as
FOR /F "tokens=1-5 delims=, " %%B IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E ?
No. Try it and see what it prints to the console.
If you wanted to start at %%B then you would need to adjust the metavariables.
FOR /F "tokens=1-5 delims=, " %%B IN ("This text will be shown. ") DO echo %%B %%C %%D %%E %%F
And what if I have:
FOR /F "tokens=2,5 delims=, " %%A IN ("This text will be shown. ") DO echo %%A %%B %%C %%D %%E
what would happen then?
It will print out 'text shown.' Always try the code and it can become clearer. It also adds %C %D %E because those metavariables haven't been defined in tokens.
In your examples the delims=, " is doing nothing, A) because there are no commas in the input text and B) because space is a default delimiter. Try removing that portion and come to grips with the tokens part first.
-
- Posts: 65
- Joined: 08 Jun 2012 07:48
Re: For Questions
Thank you. I know have a brief understanding of how the for command works... Ima go try it on some files... 
