Page 1 of 1

Warning re SHELL "DIR filespec > tempfile"

Posted: Thu Jan 19, 2006 8:40 pm
by Guest
I was running a utility program that I wrote back in 1999. Under certain conditions the program needs to do:
SHELL "DIR filespec > tempfile"

Then it reads the tempfile and selects all the filenames only, not directory names, headings, etc.

Suddenly it's not working. After much scouting I discovered that a DIR under Windows XP produces a listing much different than the original DOS 6.22 that I was using at the time I wrote the program.

I don't know exactly when Windows changed to the new DIR format, but I did some testing and came up with a DIR command which will work for DOS 6.22 and Windows XP. The secret is using the /B switch which produces a "bare" listing of only the filenames (including the subdirectory names), and combining this with the /A-D which eliminates the subdirectory names, to get only the filenames. The new SHELL becomes:
SHELL "DIR filespec /B /A-D > tempfile"

A minor additional change in my program now picks up the filenames left-justified in each record of the tempfile.

So, if you've got an old program that does a DIR to get filenames, take another look at it if you're running a newer Windows.
*****

Posted: Thu Jan 19, 2006 8:42 pm
by moneo
That was my post above. Still having those old login problems.
*****

Posted: Fri Jan 20, 2006 1:00 pm
by Zim
I did that very thing in a program I wrote in QB 3 about 6 years ago and ran under Win NT 4.

Also, you can use "DIRCMD= options" to force DIR into a particular format all the time. Then you can put that command in the AutoExec.Bat file.

Posted: Fri Jan 20, 2006 3:09 pm
by moneo
Zim wrote:.....
Also, you can use "DIRCMD= options" to force DIR into a particular format all the time. Then you can put that command in the AutoExec.Bat file.
Using the SET DIRCMD = options for setting default DIR parameters on your own PC, is fine. However, if your program is intended to run on other people's PC's, then your program cannot assume what the DIRCMD settings will be.
*****