i have wrote a batch script like below
for -f %%a in ('dir /b') do command
This script works in Windows XP but now I want to run it in Windows 3.11.
It gives a syntax error; it seems like Windows 3.1's DOS not support `for -f %%a in ('command').
Can you suggest what command can I use in Windows 3.1 to achieve equivalent functionality?
FOR /F. Loop command: against the results of another command. FOR /F processing of a command consists of reading the output from the command one line at a time and then breaking the line up into individual items of data or 'tokens'. The DO command is then executed with the parameter(s) set to the token(s) found.
Pressing "y" would use the goto command and go back to start and rerun the batch file. Pressing any other key would exit the batch file.
The cmd token records the list of arguments and the list of environment variables that are associated with a command. The cmd token contains the following fields: A token ID that identifies this token as a cmd token. A count of the command's arguments. The argument list.
In DOS 5.0, you cannot use a command inside the IN (...)
part of the statement. What you can do is the following though:
FOR -F %%A IN (*.txt) DO command
which will execute the command
for each file with the extension txt. In other words, the dir
command is implicit.
I got this information from Jeff Prosise's DOS 5. At the time indispensable, now rather dusty. Never knew I'd ever use it again ;-)
EDIT: it appeared that the indirection (see history) was not necessary. The above statement is all you need. I.e., the following works and prints each file:
FOR -F %%A IN (*.txt) DO TYPE %%A
You are correct; this syntax is not supported by Windows 3.1.
It was added by cmd.exe
in Windows NT.
I don't think you'll find an equivalent command included with Windows 3.1.
EDIT: I was wrong; see Abel's answer.
Why are you using such a pre-historic OS?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With