>FOR %a IN (AAA ? BBB /? CCC "?" DDD "/?" EEE X?X FFF X/?X GGG) DO @ECHO
"%a"
"AAA"
"BBB"
"x"
"CCC"
"DDD"
"x"
"EEE"
"FFF"
"GGG"
This is shown as entered at the prompt, but the same thing happens in a
batch file. It appears that anything with "?" in it is ignored and if it
contains "/?" it is translated into "x".
Boggle.
--
Roger Neyman
rne...@us.ibm.com
I don't get quite the same results as you (WinNT 4.0 SP6a):
C:\cmd>FOR %a IN (AAA ? BBB /? CCC "?" DDD "/?" EEE X?X FFF X/?X GGG) DO @ECHO "%a"
"AAA"
"BBB"
"CCC"
"DDD"
"EEE"
"FFF"
"GGG"
C:\cmd>FOR %a IN (AAA ? BBB /? CCC ? DDD /? EEE X?X FFF X/?X GGG) DO @ECHO "%a"
"AAA"
"BBB"
"CCC"
"DDD"
"EEE"
"FFF"
"GGG"
The problem with the question mark is because of its function as a 'wild-card'
character in file specifications.
FOR - Runs a specified command for each file in a set of files.
FOR %variable IN (set) DO command [command-parameters]
%variable Specifies a replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.
Phil Robyn
Univ. of California, Berkeley
--
u n z i p m y a d d r e s s t o s e n d e - m a i l
^ Roger Neyman wrote:
^ > >FOR %a IN (AAA ? BBB /? CCC "?" DDD "/?" EEE X?X FFF X/?X GGG) DO
@ECHO
^ > "x"
^ I don't get quite the same results as you (WinNT 4.0 SP6a):
The difference is because he has a file named 'x' in his current directory.
Frank
--
Roger Neyman
rne...@us.ibm.com
"Roger Neyman" <rne...@us.ibm.com> wrote in message
news:9sc0es$meo$1...@news.btv.ibm.com...
Yes... that turns out to be the key, sortof. Consier this sequence:
12:34 U:\>set prompt==$G
=>for %a in (AA /? BB ? CC X?X DD) DO @ECHO %a
AA
z
BB
z
CC
XzX
DD
=>del z
=>del xzx
=>for %a in (AA /? BB ? CC X?X DD) DO @ECHO %a
AA
BB
CC
DD
The presence of a file named "x" in my original experiment
is why I got different results than you did. Here it is the files
"z" and "xzx" that match.
So: it seems that the wild card is substituted IF there are any matching
files. BUT a non-wildcarded string is used as is even though there are
no matching files. Consider, for instance:
=>ECHO Whatever >AA
=>DIR /B/A-D ??
AA
=>for %a in (AA /? BB ? CC X?X DD) DO @ECHO %a
AA
BB
CC
DD
Which is identical output as before "AA" existed. So, it seems
1) there is no way to restrict the action based on the existence
of files without performing an additional test
2) there is no way to include a questionmark in the argument
list of this type of FOR loop.
This leaves me with the question as to why the "/" has no effect
at all.
Roger Neyman rne...@us.ibm.com
^ So: it seems that the wild card is substituted IF there are any matching
^ files. BUT a non-wildcarded string is used as is even though there are
^ no matching files.
I suspect that FOR doesn't look for ANY files unless there is a wild card
pattern that needs to be expanded.
^ This leaves me with the question as to why the "/" has no effect
^ at all.
These three commands should explain:
dir>"fhdakj/file"
dir C:/winnt/system32
dir "C:/winnt/system32"
But I'll add to it anyway. A slant is not permitted in a filename because
it is the switch indicator. This avoids significant confusion on the
command line. The slant IS permitted in a quoted file path because, I
assume, the quotes prevent that confusion and because MS wants to grow up
and be like UNIX someday.
Frank
>>FOR %a IN (AAA ? BBB /? CCC "?" DDD "/?" EEE X?X FFF X/?X GGG) DO @ECHO
> "%a"
> "AAA"
> "BBB"
> "x"
> "CCC"
> "DDD"
> "x"
> "EEE"
> "FFF"
> "GGG"
> This is shown as entered at the prompt, but the same thing happens in a
> batch file. It appears that anything with "?" in it is ignored and if it
> contains "/?" it is translated into "x".
You have a file named x in your root directory, and only x. You have no
single letter files in your directory that you are running the batchfile.
? and * are wild cards, and the FOR command looks for files if you use a
wild card.
I haven't found a way to escape or quote the ? to make it do what you want
it to do. So I can't help you make it work, but I can at least tell you
why it's doing what it's doing.
Bryan
There used to be an undocumented command in the config.sys file.
SWITCHAR=-
That would use - as the switch character for MOST programs.
That also allowed you to use / as the path separator.
As opposed to TRS-DOS which used / as the extension separator!
I forget if it was DOS 4, 5 or 6 that SWITCHAR was no longer
valid, although it was still visible in 6.X command.com.
Bryan
^ There used to be an undocumented command in the config.sys file.
^
^ SWITCHAR=-
^
^ That would use - as the switch character for MOST programs.
I vaguely remember something like that, and it had a very tight
specification compared to the rest of the config.sys entries. That was in
the days when a lot of the available programs were ports from UNIX, which
uses '-' instead of '/'.
Frank
Frank wrote:
> ^ This leaves me with the question as to why the "/" has no effect
> ^ at all.
<snip>...
>... A slant is not permitted in a filename because
> it is the switch indicator. This avoids significant confusion on the
> command line. The slant IS permitted in a quoted file path because, I
> assume, the quotes prevent that confusion and because MS wants to grow up
> and be like UNIX someday.
*laugh*
Quite so... (and, I might add, like VMS was 20 yrs ago)
Now all the pieces fit. Thanks to all who repsonded
--
Roger Neyman
rne...@us.ibm.com