Warning re SHELL "DIR filespec > tempfile"

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
Guest

Warning re SHELL "DIR filespec > tempfile"

Post 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.
*****
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

That was my post above. Still having those old login problems.
*****
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Post 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.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post 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.
*****
Post Reply