BBS: Inland Empire Archive
Date: 12-02-92 (18:21)             Number: 392
From: JOHN GALLAS                  Refer#: NONE
  To: ROBERT ROOD                   Recvd: NO  
Subj: DIRECTORY                      Conf: (2) Quik_Bas
RR>Whats the easiest way to get a list of files out of a directory. Like all
RR>the files that end with *.dat. Right now im using the SHELL command but
RR>this takes too long. Can anyone help?

If you're using QuickBASIC, you can load up QB with the QB.QLB library
(QB /L QB.QLB) and run this function:  (you can use wildcards in it!)

'DIR.BAS by Dave Cleary
'One of the most useful additions to BASIC 7 PDS is the DIR$ function.
'This function allows you to read a directory of filenames. It also
'allows you to check the existence of a file by doing the following:
'     PRINT "File Found"
'     PRINT "File not found"
'Now QuickBASIC 4.X users can have this useful function for their
'Calling DIR$ with a FileSpec$ returns the the name of the FIRST
'matching file name. Subsequent calls with a null FileSpec$ return the
'NEXT matching file name. If a null string is returned, then no more
'matching files were found. FileSpec$ can contain both a drive and a
'path plus DOS wildcards. Special care should be taken when using
'this on floppy drives because there is no check to see if the drive
'is ready.


     '$INCLUDE: 'QB.BI'

     '-----  Some constants that DIR$ uses
     CONST DOS = &H21
     CONST SetDTA = &H1A00, FindFirst = &H4E00, FindNext = &H4F00

'This shows how to call DIR$ to find all matching files 'CLS 'FileSpec$ = "C:\QB\SOURCE\*.BAS" 'Found$ = DIR$(FileSpec$) 'DO WHILE LEN(Found$) ' PRINT Found$ ' Found$ = DIR$("") 'LOOP '
FUNCTION DIR$ (FileSpec$) STATIC DIM DTA AS STRING * 44, Regs AS RegTypeX Null$ = CHR$(0) '----- Set up our own DTA so we don't destroy COMMAND$ Regs.AX = SetDTA 'Set DTA function Regs.DX = VARPTR(DTA) 'DS:DX points to our DTA Regs.DS = -1 'Use current value for DS InterruptX DOS, Regs, Regs 'Do the interrupt '----- Check to see if this is First or Next IF LEN(FileSpec$) THEN 'FileSpec$ isn't null, so 'FindFirst FileSpecZ$ = FileSpec$ + Null$ 'Make FileSpec$ into an ASCIIZ 'string Regs.AX = FindFirst 'Perform a FindFirst Regs.CX = 0 'Only look for normal files Regs.DX = SADD(FileSpecZ$) 'DS:DX points to ASCIIZ file Regs.DS = -1 'Use current DS ELSE 'We have a null FileSpec$, Regs.AX = FindNext 'so FindNext END IF InterruptX DOS, Regs, Regs 'Do the interrupt '----- Return file name or null IF Regs.Flags AND 1 THEN 'No files found DIR$ = "" 'Return null string ELSE Null = INSTR(31, DTA, Null$) 'Get the filename found DIR$ = MID$(DTA, 31, Null - 30) 'It's an ASCIIZ string starting END IF 'at offset 30 of the DTA END FUNCTION * OLX 2.1 TD * Don't gripe--VOTE! --- RyPacker v2.5b * Origin: The Ghost Mode - An RyBBS System! (612)-688-0026 (1:282/3006)
Outer Court
Echo Basic Postings

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