views:

121

answers:

2

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?

+1  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?

SLaks
+7  A: 

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
Abel
A little note: there should be *no quotes* around `*.txt`, those were not supported at the time (spaces in filenames or long filenames were not supported anyway).
Abel
The equivalent to the original question would be `(*)`, not `(*.txt)`.
Eli Acherkan
Abel: While the quotes didn't exist, spaces were indeed legal in MS-DOS file names: http://blogs.msdn.com/oldnewthing/archive/2009/07/09/9825126.aspx
Joey
@Rössel: interesting. I was aware of that, but was under the impression that internally, spaces were replaced with Ext-ASCII 0xFF, but apparently that assumption was false (it's all 15 years ago...)
Abel