Microsoft KB Archive/83811

= QB 4.x/Basic 7.x Example to List Subdirectories in Given Path =

Article ID: 83811

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q83811



SUMMARY
This article demonstrates how to obtain a list of all subdirectories for a given path using the CALL INTERRUPT and CALL INTERRUPTX routines. In this example, the Basic INTERRUPT routines invoke MS-DOS interrupt service calls (SetDTA, FindFirst, and FindNext) to retrieve all files in the specified directory. As each file is retrieved, its attributes are checked to determine if the file is a subdirectory. If the file is a subdirectory, then the directory name is displayed.



MORE INFORMATION
For a similar example that loads an MS-DOS directory listing into an array, query in the Microsoft Knowledge Base on the following words:

Example and Load and Directory and Listing and Array

To make this example work in Basic PDS 7.0 or 7.1, modify the FirstFile function in the example below as follows:

 Include the QBX.BI file instead of the QB.BI file. DIM inregs as RegTypeX and outregs as RegTypeX. Change CALL INTERRUPT to CALL INTERRUPTX.  Add the following line between the assignment for INREGS.DX and the CALL INTERRUPTX: inregs.ds = SSEG(FileName$) 

Example
DECLARE SUB SetDTA (DTABuffer AS ANY) DECLARE FUNCTION FindFirstFile& (path$) DECLARE FUNCTION FindNextFile&

' $INCLUDE: 'qb.bi'       ' 1. Use QBX.BI for PDS

TYPE DTABufferType Reserved    AS STRING * 21 Attributes  AS STRING * 1 CreateTime  AS INTEGER Accessdate  AS INTEGER FileSize    AS LONG FileName    AS STRING * 13 END TYPE

DIM DTABuffer AS DTABufferType

CLS path$ = &quot;c:\&quot; CALL SetDTA(DTABuffer)                     'Set DTA IF (FindFirstFile(path$) = 0) THEN DO   IF DTABuffer.Attributes = CHR$(16) THEN 'If file is a directory PRINT RTRIM$(DTABuffer.FileName) END IF   CALL SetDTA(DTABuffer) LOOP WHILE (FindNextFile = 0) END IF END

FUNCTION FindFirstFile& (path$) ' 2. Use RegTypeX below for PDS DIM inregs AS RegType, outregs AS RegType

inregs.ax = &H4E00 inregs.cx = 16         'include directories in search FileName$ = path$ + &quot;*.*&quot; + CHR$(0) inregs.dx = SADD(FileName$) ' 3. Add this for PDS: inregs.ds = SSEG(Filename$) CALL interrupt(&H21, inregs, outregs) '4. Use INTERRUPTX for PDS FindFirstFile& = (outregs.ax AND &HF)

END FUNCTION

FUNCTION FindNextFile& DIM inregs AS regtype, outregs AS regtype

inregs.ax = &H4F00 CALL interrupt(&H21, inregs, outregs) FindNextFile = (outregs.ax AND &HF) END FUNCTION

SUB SetDTA (DTABuffer AS DTABufferType) DIM inregs AS RegTypeX, outregs AS RegTypeX

DTABuffer.CreateTime = 0            ' Clear DTABuffer DTABuffer.Attributes = &quot; &quot; DTABuffer.Accessdate = 0 DTABuffer.FileSize = 0 DTABuffer.FileName = SPACE$(13)

inregs.ax = &H1A00                  ' Set DTA address inregs.ds = VARSEG(DTABuffer) inregs.dx = VARPTR(DTABuffer) CALL interruptX(&H21, inregs, outregs)

END SUB

