I have a few basic questions that I don't understand what they do.
In this example;
for /f "tokens=* delims= " %%a in ('dir/b "C:\Documents and Settings" ^| find /n /v "\\\"')
I understand the for /f "tikens=* delims=" but what does the 'dir do exactly, or is that the outter quotes?
What is the ^| do? and
I see find /n /v is just swithces but what with the 3 slashes? "\\\"
Is there someone I can ask these questions directly or is using the form the best method. I've done weeks of research in some of these little operators and still don't understand them.
Command operators
Moderator: DosItHelp
Re: Command operators
crobertson wrote:I have a few basic questions that I don't understand what they do.
In this example;
for /f "tokens=* delims= " %%a in ('dir/b "C:\Documents and Settings" ^| find /n /v "\\\"')
I understand the for /f "tikens=* delims=" but what does the 'dir do exactly, or is that the outter quotes?
What is the ^| do? and
I see find /n /v is just swithces but what with the 3 slashes? "\\\"
Is there someone I can ask these questions directly or is using the form the best method. I've done weeks of research in some of these little operators and still don't understand them.
dir /b "C:\Documents and Settings" will list all visible files and folder in \Documents and Settings. The /b switch stands for "bare": "bare listing", i.e., only file/folder names.
^| is the pipe operator. In this case it is escaped (with ^) because it'll be parsed by the FOR loop; outside the loop, you could write the code in the same way without escaping the pipe:
Code: Select all
dir/b "C:\Documents and Settings"|find /n /v "\\\"
What does it do?
For instance, say we have command1 and command2. You need the output of command1 to be the input of command2.
One way of doing this is,
Code: Select all
command1 >tmpfile.tmp
command2 <tmpfile.tmp
del tmpfile.tmp
But why would you use these 3 lines of code if you could just use 1?
Code: Select all
command1|command2
Example:
say you have CHOICE on your machine.
Code: Select all
echo Y|choice /c:YN /n "Can you see this? "
if %errorlevel% == 1 echo You can see this!
The output of echo Y (i.e. Y) would be the input of choice.
It's just like you've actually typed Y in CHOICE prompt, but you "did" it before the prompt even showd.
The 3 back slashes \\\ is what FIND is NOT trying to find in DIR.
Re: Command operators
To process only directories you would normally add /a:d to the DIR command.
That loop is numbering every item in the DIR /b command presumably for use in the following routine. The "\\\" is used because it will never appear in the filenames or folders so it "numbers every item not having \\\ in it"
It could have simply been find /n /v "" and it would do the same.
This is ambiguous - you normally have "tokens=*" or "delims=" to use the entire line. They are not the same as Tokens=* does not always take the entire line, but filters out some leading characters in some cases.
"tokens=* delims= " are conflicting commands but tokens=* takes precedence there I think.
That loop is numbering every item in the DIR /b command presumably for use in the following routine. The "\\\" is used because it will never appear in the filenames or folders so it "numbers every item not having \\\ in it"
It could have simply been find /n /v "" and it would do the same.
This is ambiguous - you normally have "tokens=*" or "delims=" to use the entire line. They are not the same as Tokens=* does not always take the entire line, but filters out some leading characters in some cases.
"tokens=* delims= " are conflicting commands but tokens=* takes precedence there I think.
-
- Posts: 20
- Joined: 25 May 2012 12:34
Re: Command operators
is there a site or book that details all this?
Re: Command operators
Greetings crobertson,
You are at the best site for batch file questions/problems
as demonstrated by the explanations supplied by Fawers and
foxidrive (well done guys!)
I do not know of any book but you may want to have a look
here:
http://www.netikka.net/tsneti/info/tscmd.php
Otherwise, post back with more questions. The folks here are
like 'bums on a ham sandwich' when it comes to batch file
solutions and explanations.
Best wishes!
I forgot this is an international forum. In the USA a bum is a lazy person that would jump on a free meal.
You are at the best site for batch file questions/problems
as demonstrated by the explanations supplied by Fawers and
foxidrive (well done guys!)
I do not know of any book but you may want to have a look
here:
http://www.netikka.net/tsneti/info/tscmd.php
Otherwise, post back with more questions. The folks here are
like 'bums on a ham sandwich' when it comes to batch file
solutions and explanations.
Best wishes!
I forgot this is an international forum. In the USA a bum is a lazy person that would jump on a free meal.
Re: Command operators
'crobertson wrote:is there a site or book that details all this?
Of course there are, when I was young every OS you bought would come with a book,
I have a book called Tulip MS-DOS 5.0, it used to be new but I used it so much, it is falling apart.
It got me hooked on computers, in those days you only had to own a pc in order to be considered a programmer.
These books teach you much more than just writing batch files, they explain how computers work. How memory is addressed and introduce u to other languages like QBasic.
Ask some gray person with a beard and glasses at your local library