Re: directory tree

 BBS: Inland Empire Archive
Date: 11-30-92 (18:54)             Number: 311
From: PAUL LANKOW                  Refer#: NONE
  To: DENIS DUBUC                   Recvd: NO  
Subj: Re: directory tree             Conf: (2) Quik_Bas
DD>  > Can someone post some code to read the directory tree?

     This routine doesn't return a TREE as such, but it does return the name
of every directory for the specified drive. It was written for PDS, but will
work in QB with the noted modifications. When the routine is done, the number
of directories (including the root) is returned in COUNT with ARRAY$()
populated with the names.

'=============================================================================
'A recursive routine that returns all directories on a drive. On entry, supply
'the drive letter in drive$, make sure COUNT is zero, and dimension ARRAY$()
'to the maximum number of directories you're likely to encounter. There is no
'error checking for empty floopy drives or array too small.
'=============================================================================
'$INCLUDE: 'qbx.bi'          'Change to 'qb.bi' for qb
DEFINT A-Z

SUB zalldirs (drive$, count, array$())
DIM r AS regtypex
search$ = drive$                                   'reassign string since it
IF count = 0 THEN                                  ' gets changed in routine
  search$ = UCASE$(search$)                        'make upper case
  IF LEN(search$) = 1 THEN search$ = search$ + ":" 'define search
  search$ = LEFT$(search$, 2)
  count = 1
  array$(count) = search$ + "\"
END IF

zero$ = CHR$(0): dta$ = SPACE$(43)     'define ZERO and DTA
search$ = search$ + "\"
srch$ = search$ + "*" + zero$          'dos requires zero terminated string

'get original dta
r.ax = &H2F00
interruptx &H21, r, r
sgmt = r.es: ofst = r.bx               'save segment and offset of dta
mode = &H4E00                          'set mode to FINDFIRST

'set our dta
DO
 r.ax = &H1A00
 r.ds = SSEG(dta$): r.dx = SADD(dta$)  'change SSEG to VARSEG in qb
 interruptx &H21, r, r                 'tell dos where this dta is

 r.ax = mode                           'findfirst, or findnext
 r.cx = 16                             'look for directories
 r.ds = SSEG(srch$): r.dx = SADD(srch$)'change SSEG to VARSEG in qb
 interruptx &H21, r, r                 'find one
 IF (r.flags AND 1) THEN EXIT DO       'if none, bail
 f.attr = ASC(MID$(dta$, 22))          'attribute in f.attr
 tmp$ = MID$(dta$, 31) + zero$
 f.name$ = LEFT$(tmp$, INSTR(tmp$, zero$) - 1)  'directory name in f.name
 mode = &H4F00                         'change mode to FINDNEXT
 IF ASC(f.name$) <> 46 THEN            'we don't want '.' or '..'
   IF f.attr = 16 THEN                 'make sure it's a directory
     count = count + 1                 'increment count
     s$ = search$ + f.name$            'full path name
     array$(count) = s$                'add to array
     zalldirs s$, count, array$()      'look for some dirs here
   END IF
 END IF
LOOP
r.ax = &H1A00
r.ds = sgmt: r.dx = ofst               'return original dta segment & offset
interruptx &H21, r, r

END SUB


 * SLMR 2.1a *


--- WM v2.04/92-0634
 * Origin: DON'T PANIC! Resistance is USELESS! 206-573-9411 (1:105/107)
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