Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For loop in Windows 3.1 DOS

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?

like image 956
issac Avatar asked Dec 20 '09 17:12

issac


People also ask

Can I use for loop in CMD?

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.

How do I loop a batch file in Windows?

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.

What are tokens in CMD?

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.


2 Answers

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
like image 79
Abel Avatar answered Dec 24 '22 14:12

Abel


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?

like image 42
SLaks Avatar answered Dec 24 '22 14:12

SLaks