This is only a preview of the October 1994 issue of Silicon Chip. You can view 33 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Beginner's Dual Rail Variable Power Supply":
Items relevant to "Build A Talking Headlight Reminder":
Items relevant to "Electronic Ballast For Fluorescent Lights":
Items relevant to "Computer Bits":
Articles in this series:
|
COMPUTER BITS
BY DARREN YATES
Placing directories into programs
Unless you have Visual BASIC or some other
high level language, getting DOS directories into
your programs is not always easy. This month,
we show you how you can do it with QBasic and
QuickBASIC 4.5.
This month’s column is the result
of a letter from a reader wanting to
know how to get a directory listing from the screen into one of his
programs. This is actually a quite
common thing to do, particularly if
you work with Windows or Visual
BASIC. However, it’s a little more
difficult to do it in Quick BASIC than
just clicking on an icon.
Firstly, there is no direct command
in BASIC you can use apart from the
FILES command and this simply
displays a list of files on the screen.
You can determine which files come
up –not how they appear – by using
the familiar wildcard commands. In
fact, the files appear pretty much as
they would get if you used the DOS
command “DIR/W”. Most of the time,
this isn’t very useful, particularly if
you type FILES C:|WINDOWS (for
example) and 100+ files fly past your
eyes, or if you need to know the size
of a certain file before loading it into
the system.
For QuickBASIC users, there are
essentially two methods. The first is
to take it directly from the drive. This
can be done using some extra DOS interrupts that we have yet to cover. You
can do what’s called an “absolute read”
of a certain sector of a track where DOS
stores this information.
This is by far the most elegant method but it can be dangerous if you plug
in the wrong command. It doesn’t take
much to rewrite your directory and
upset the whole disc. It’s also fairly
88 Silicon Chip
difficult to do and that’s with the right
information at hand.
The DOS interrupts also allow you
to do an “absolute write” to any sector of any track but you don’t get any
second warnings. In fact, you don’t
even get a first warning that you will
lose any information currently stored
in that location. It simply wipes over
the top.
The redirect command
The second method is more cumbersome but is much safer and easier
to do. It involves using the DOS redirect command, “>”. Every time you
do a DIR in DOS, your PC directs the
directory output to your screen so
you can see all of the files. However,
by using the “>” command, you can
direct this output into an ASCII file
on disc.
For example, if you type the command “DIR > DIRLIST.TXT”, DOS will
create the file DIRLIST.TXT and dump
the complete list
ing of the current
directory into that file. You can then
use EDIT to do what you like with that
file. More importantly, you can now
use Quick/QBasic to do what you like
with the file.
The good thing about the file is that
it is columnated; ie, each subpart of
the directory listing begins at a particular column. For example, the first
part of the filename begins at column
1 and has a maximum of eight letters;
the three-letter maximum extension
begins at column 10. The size of the
file begins at column 14 and the start
of the date at column 24. And finally,
the time begins at column 34.
You can easily extract each of these
five file parameters by using the MID$
command. An example of this is
shown in the program DIRSPLIT.BAS
– see listing.
This program is designed to handle
a directory which has up to 400 files. If
you expect to have a bigger directory,
simply extend the dimension from 400
to whatever you think you need. The
next series of dimension statements
set up our five parameter arrays, one
each for filename, extension, file size,
date and time.
Using the LINE INPUT statement to
read in one line of the directory listing
at a time, the WHILE NOT EOF(1) loop
and the MID$ command enables us to
extract each of the parameters. These
parameters are then stored in suitably
named arrays: FILENAME, EXTENSION, FILESIZE, DATE and TIME. The
dimension of each array is arranged
so that the first element of each array
refers to one file, the next element to
the next file and so on.
The second half of the program
prints this information on screen.
The TAB statements ensure that the
directory listing uses the whole screen
rather than just half of it as the normal
DIR statement uses.
The VIEW PRINT command allows
the top two lines (ie, the column titles)
to stay on screen at all times, while the
FOR NEXT loop enables you to page
through the directory. This is handy
when you have more than one screen
of files in a directory.
To run the program, you simply type
DIRSPLIT<enter> and it will display
the contents of the current disc and
directory.
Copies of DIRSPLIT.BAS/OBJ/EXE
will be available on 3.5-inch or 5.25-
Basic Listing For Dirsplit.bas Utility
• TOROIDAL
• CONVENTIONAL
• POWER • OUTPUT
• CURRENT • INVERTER
• PLUGPACKS
• CHOKES
DIM dirline$(400)
DIM filename(400) AS STRING * 8
DIM extention(400) AS STRING * 3
DIM filesize(400) AS STRING * 9
DIM date(400) AS STRING * 8
DIM time(400) AS STRING * 7
start = 0
SHELL “DIR > DIRLIST.TXT”
OPEN “dirlist.txt” FOR INPUT AS #1
WHILE NOT EOF(1)
lineno = lineno + 1
LINE INPUT #1, dirline$
‘FILENAME
filename(lineno) = MID$(dirline$, 1, 8)
‘EXTENSION
extension(lineno) = MID$(dirline$, 10, 3)
‘FILESIZE
filesize(lineno) = MID$(dirline$, 14, 9)
‘DATE
date(lineno) = MID$(dirline$, 24, 8)
‘TIME
time(lineno) = MID$(dirline$, 34, 7)
WEND
CLOSE #1
CLS
PRINT TAB(1); “File”; TAB(15); “extension”; TAB(30); “File size”; TAB(50); “Date”;
TAB(70); “Time”
PRINT “————————————————————————————”
VIEW PRINT 3 TO 24
WHILE linenum < lineno
FOR linenum = start + 5 TO start + 24
IF linenum > lineno - 2 THEN GOTO endnext
PRINT TAB(1); filename(linenum);
PRINT TAB(15); extention(linenum);
PRINT TAB(30); filesize(linenum);
PRINT TAB(50); date(linenum);
PRINT TAB(70); time(linenum);
endnext:
NEXT linenum
PRINT : PRINT “Press <ENTER> key to continue. . .”
a$ = INPUT$(1)
start = start + 19
WEND
inch discs for $7 plus $3 p&p from
SILICON CHIP, PO Box 139, Collaroy
Beach, NSW 2097. Alternatively, you
TRANSFORMERS
can order by phoning (02) 979 5644
or faxing (02) 979 6503 and quoting a
SC
credit card number.
STOCK RANGE TOROIDALS
BEST PRICES
APPROVED TO AS 3108-1990
SPECIALS DESIGNED & MADE
15VA to 7.5kVA
Tortech Pty Ltd
24/31 Wentworth St, Greenacre 2190
Phone (02) 642 6003 Fax (02) 642 6127
Silicon Chip Binders
These beautifully-made binders
will protect your copies of SILICON
CHIP. They are made from a dis
tinctive 2-tone green vinyl & will
look great on your bookshelf.
Price: $A11.95 plus $3 p&p each
(NZ $6 p&p). Send your order to:
Silicon Chip Publications
PO Box 139
Collaroy Beach 2097
Or fax (02) 979 6503; or ring (02)
979 5644 & quote your credit card
number.
October 1994 89
|