BBS: Inland Empire Archive Date: 06-10-93 (09:21) Number: 250 From: DAVE ARIGAN Refer#: NONE To: BENNETT HENDRY Recvd: NO Subj: Re: DIRS Conf: (2) Quik_Bas
-=> Quoting Bennett Hendry to All <=-
BH> Does anybody know of a good way to read directories from a disk into a
BH> variable? (like an array, perhaps?) I want to write a recursive
BH> routine to remove an entire directory branch, with full
BH> sub-directories, but I can't get the directory names into a variable
BH> in order to work with them. ANY ideas would be appreciated.
The following reads a directory using Qbasic. With some modifications,
you should have no problems adapting it to your program. Remember, use:
C:\QBASIC>qb /l lib\qb.qlb
DEFINT A-Z '$INCLUDE: 'QB.BI'
TYPE DataTransferArea
Reserved1 AS STRING * 21
Attribute AS STRING * 1
FileTime AS INTEGER
FileDate AS INTEGER
FileSize AS LONG
FIleName AS STRING * 13
END TYPE
TYPE DirectoryRecord
FIleName AS STRING * 13
FileSize AS LONG
FileDate AS INTEGER
FileTime AS INTEGER
FileAttb AS INTEGER
END TYPE
DIM SHARED InRegsX AS RegTypeX
DIM SHARED OutRegsX AS RegTypeX
DIM SHARED DTA AS DataTransferArea
DIM DirEntry AS DirectoryRecord
CLS
INPUT "Enter file specification: "; filespec$
CALL SetDTA(DTA)
FindStatus = FindFirst(0, filespec$, DirEntry)
CALL PrintDirEntry(DirEntry, FindStatus)
FindStatus = FindNext(DirEntry)
WHILE FindStatus = 0
CALL PrintDirEntry(DirEntry, FindStatus)
FindStatus = FindNext(DirEntry)
CALL SetDTA(DTA)
WEND
END
FUNCTION FindFirst (Attr, FIleName$, DEntry AS DirectoryRecord)
InRegsX.AX = &H4E00
InRegsX.CX = Attr
Spec$ = FIleName$ + CHR$(0)
InRegsX.DS = VARSEG(Spec$) ' Load DS:DX with
InRegsX.DX = SADD(Spec$) ' address of Spec$
CALL InterruptX(&H21, InRegsX, OutRegsX)
FindFirst = OutRegsX.AX
IF (OutRegsX.Flags AND 1) = 0 THEN
CALL TransferDTA2DIR(DEntry)
FindFirst = 0 'Clear error condition setting
END IF
END FUNCTION
FUNCTION FindNext (DEntry AS DirectoryRecord)
DTA.FIleName = SPACE$(13)
InRegsX.AX = &H4F00
CALL InterruptX(&H21, InRegsX, OutRegsX)
FindNext = OutRegsX.AX
IF (OutRegsX.Flags AND 1) = 0 THEN
CALL TransferDTA2DIR(DEntry)
FindNext = 0
END IF
END FUNCTION
FUNCTION FmtDate$ (FDate)
Day = FDate AND &H1F
Month = (FDate AND &H1E0) \ 32
Year = (FDate AND &HFE00) \ 512 + 1980
FmtDate$ = RStr$(Month, 2) + "-" + RStr$(Day, 2) + "-" +
RStr$(Year, 4)
END FUNCTION
FUNCTION FmtTime$ (T%)
Seconds = (T% AND &H1F) * 2
Minutes = (T% AND &H7E0) \ 32
Hours = (T% < 0) * (-16) + ((T% AND &H7FFF) \ 2048)
Abbr$ = " am"
IF Hours = 12 THEN Abbr$ = " pm"
IF Hours = 0 THEN Hours = 12
IF Hours > 12 THEN
Hours = Hours MOD 12
Abbr$ = " pm"
END IF
FmtTime$ = RStr$(Hours, 2) + ":" + RStr$(Minutes, 2) + ":" +
RStr$(Seconds, 2)
END FUNCTION
SUB PrintDirEntry (DR AS DirectoryRecord, FindStatus)
FmtStr$ = "\ \ ##,###,### " + "\ \ \
\ ###"
IF FindStatus = 0 THEN
PRINT USING FmtStr$; DR.FIleName; DR.FileSize;
FmtDate$(DR.FileDate); FmtTime
ELSE
PRINT "Error on file lookup"
SELECT CASE FindStatus
CASE 2 PRINT "File not found"
CASE 3 PRINT "Path not found"
CASE 18 PRINT "Match not found"
CASE ELSE PRINT "Unknown error #"; FindStatus
END SELECT
END IF
END SUB
FUNCTION RStr$ (X%, LX%)
X$ = STR$(X%)
RStr$ = RIGHT$("00000" + RIGHT$(X$, LEN(X$) - 1), LX%)
END FUNCTION
SUB SetDTA (DTA AS DataTransferArea)
InRegsX.AX = &H1A00
InRegsX.DS = VARSEG(DTA)
InRegsX.DX = VARPTR(DTA)
CALL InterruptX(&H21, InRegsX, OutRegsX)
END SUB
SUB TransferDTA2DIR (DEntry AS DirectoryRecord)
DEntry.FIleName = DTA.FIleName
DEntry.FileSize = DTA.FileSize
DEntry.FileDate = DTA.FileDate
DEntry.FileTime = DTA.FileTime
DEntry.FileAttb = ASC(DTA.Attribute)
END SUB
$$
... It's only a hobby ... only a hobby ... only a
--- FMail 0.94
* Origin: CzarLand BBS * Windsor, ON * Canada (1:246/27.0)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET