For a loop in Windows 3.1 DOS

I wrote a script package as shown below

for -f %%a in ('dir /b') do command 

This script works on Windows XP, but now I want to run it on Windows 3.11.

It gives a syntax error; Windows 3.1 DOS does not seem to support `for -f %% a in ('command').

Can you suggest which command I can use in Windows 3.1 to achieve equivalent functionality?

+7
batch-file
source share
2 answers

In DOS 5.0, you cannot use the command inside the IN (...) part of the instruction. However, you can do the following:

 FOR -F %%A IN (*.txt) DO command 

which will execute command for each file with the txt extension. In other words, the dir command is implicit.

I received this information from Jeff Prosise DOS 5. At that time, indispensable, now quite dusty. I never knew that I would ever use it ,-)

EDIT: It turned out that indirection (see history) is not required. The above expression is all you need. Ie, the following works and prints each file:

 FOR -F %%A IN (*.txt) DO TYPE %%A 
+8
source share

You're right; This syntax is not supported by Windows 3.1.
It was added by cmd.exe in Windows NT.

I do not think that you will find the equivalent command included in Windows 3.1.
EDIT : I was wrong; see Abel's answer.

Why are you using such a prehistoric OS?

+1
source share

All Articles