Post by Marshall PricePost by Todd VargoPost by John SavagePost by Marshall PriceBut what I really don't understand is how FOR can sometimes interpret
what's in the parentheses as filespecs and sometimes as other things,
such as strings or commands. Is there something tricky there, or is it
perfectly sensible? (The syntax help only confuses me.)
That sounds like NT stuff; you'll need to ask on a windows group for
help with that.
I don't see why it sounds like NT stuff. The following are perfectly legal
FOR commands in MSDOS/Win9x/Me systems.
::1 Wildcards return existing files.
FOR %? in (*.txt) DO ECHO %?
::2 Strings contain no wildcards.
FOR %? in (filename.exe foo bar 1 2 3) DO echo %?
::%? contains the strings regaurdless of if it exists
::3 Commands are same #2 (except position of %? is moved).
FOR %? in (SHIFT ECHO CALL DEL GOTO:LABEL) DO %? filename.bat
::4 Combinations
FOR %? in (fo?.bat del:foo.bat) DO call %?
You're right; I'm not talking about NT stuff. But I'm still terribly
confused, as you shall see! :-)
Shall I take your :-) above as meaning the remainder is trolling? Hmmm...
Post by Marshall PriceIs it a general rule that any item within the parentheses that contains
a wildcard refers to files in the current directory, while anything that
doesn't is a string, though it can be used to identify a file or command
in the DO part?
In general, yes, except "current directory" only applies if you have not
specified a directory.
CD c:\windows
FOR %? in (c:\abc\123\*.txt) do echo %?
Clearly, above does not refer to "current directory".
Post by Marshall PriceFirst, I take it that the question mark in "%?" behaves just like a
letter of the alphabet. That is, it's not a wildcard, right?
This is your second question so it can not be "First".
Second, you have taken it correctly.
Post by Marshall PriceIn example 3, the SHIFT boggles my mind! I thought it was only used
within .BAT files and took no arguments.
SHIFT filename.bat
ECHO filename.bat
CALL filename.bat
DEL filename.bat
GOTO:LABEL filename.bat
Does the GOTO escape from the FOR loop? How does that work? Does it
run filename.bat with an immediate jump to LABEL somehow, and fail
gracefully if LABEL isn't in filename.bat?
Isn't filename.bat already deleted?!
Well, since SHIFT AND GOTO only apply to batch files, the %? should be %%?,
but the point in this example was that you can place a list of commands in
the parenthesis, not that they must be used in this exact order or exactly
like this. As for SHIFT and GOTO not taking arguments, you are correct,
however, by simply trying yourself before asking, you would have found the
argument is ignored for these commands and does not cause a batch halting
error.
Post by Marshall PriceCALL FOA.BAT
DEL FOO.BAT
CALL FOB.BAT
DEL FOO.BAT
CALL FOC.BAT
DEL FOO.BAT
Right? (The colon in "del:foo.bat" is new to me. I don't understand it.)
Well, assuming you are writing a batch file that does something productive,
it is up to the author to assure there would not be a FOA, FOB or FOC to
interfere with operation.
Post by Marshall PriceIs there an attempted CALL of FOO.BAT, even though it's gone?
You are reading the examples as being intended for a specific purpose based
on incorrect assumptions.
Post by Marshall PriceCALL FOA.BAT DEL:FOO.BAT
CALL FOB.BAT DEL:FOO.BAT
CALL FOC.BAT DEL:FOO.BAT
CALL FOA.BAT
CALL FOB.BAT
CALL FOC.BAT
CALL DEL:FOO.BAT
As I indicated above, if the batch author wrote code to assure FOA, FOB and
FOC would not exist, then all it would do is CALL and DEL FOO.BAT as the
author intended.
For example...
@echo off
for %%? in (md cd) do %%? mytmp
echo do something useful>foo.bat
for %%? in (call del) do %%? foo.bat
for %%? in (cd.. rd:mytmp) do %%?
That said, my post was not intended to be a one stop newcomer instruction
manual, rather a demonstration that it does require NT to perform these
actions as my "I don't see why it sounds like NT stuff" lead-in indicated.
Sorry if anyone read more into the examples than was intended. Think outside
the box!
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
--
Posted via a free Usenet account from http://www.teranews.com