DECLARE FUNCTION DQBdir$ (Mask AS STRING, Attrib AS INTEGER)
Mask - Mask for file(s) to search for
Attrib - Attributes of the file(s) to search for
A STRING holding the filename of the next file found
DQBdir scans the directory for the files matching specified mask; the mask can include full path and wildcards, and you can also use Windows long filenames. If no files are found, the function returns a null string. The first time DQBdir is called with a mask, it searches for the first file matching it; if a file is found, then you can continue to scan the directory by calling this function again, but by passing a null string as mask. Repeat this process until you get a null string, and you'll obtain a full directory scan. The attrib parameter specifies which kind of files to search for: there are constants made up for you, which you can also sum to search for a larger variety of files (for example, to search simultaneously for normal archive files and directories), so just take a look at appendix A for them.
A hint: you can determine if a file exists by simply checking if DQBdir$ of that file as mask, with ATTRIB.A as attribute, gives a null string or the file name itself... See also DQBdrive$, DQBpath$, DQBnumDrives, DQBsetDrive, DQBchDir
*****************************************************************************
' All integers for speed
DEFINT A-Z
'$INCLUDE:'DIRECTQB.BI'
' Let's initialize the library with no layers nor sounds nor EMS
IF DQBinit(0, 0, 0) THEN DQBclose: PRINT DQBerror$: END
CLS
' Prints available drives
PRINT "Available drives: ";
FOR i = 1 TO DQBnumDrives
PRINT "[" + CHR$(64 + i) + "] ";
NEXT i
PRINT
' Prints volume label
PRINT "Current volume label is " + DQBdir$("*.*",ATTRIB.L)
' Prints current drive and directory
PRINT "Directory of " + DQBdrive$ + ":\" + DQBpath$
' Let's search for normal archive ".BAS" files
File$ = DQBdir$("*.BAS", ATTRIB.A)
IF File$ = "" THEN
' No files matching
PRINT "No .BAS files found!"
ELSE
' A first file was found! Let's print it
PRINT File$
' Now we search for the next files... if any
DO
' This second time we don't need the mask nor the attributes
File$ = DQBdir$("",0)
' If no more files are found, then exit the loop
IF File$ = "" THEN EXIT DO
' Prints our next file
PRINT File$
LOOP
END IF
' Waits for the user to press a key
WHILE INKEY$ = "": WEND
' Ends program
DQBclose
*****************************************************************************