issac
issac

Reputation: 81

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?

Upvotes: 8

Views: 721

Answers (2)

SLaks
SLaks

Reputation: 887375

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?

Upvotes: 1

Abel
Abel

Reputation: 57159

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

Upvotes: 8

Related Questions