TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: CHRISTIAN SCHULZ
from: ERIC SCHONNING
date: 1995-07-22 11:10:00
subject: Re: Directory

CS> I'm searching for an algorithm or a function that help me in read the
CS> complete
CS> directory structures. If anybody has something like that, please post 
CS> via netmail to me !!!!
 
here is an older version of a tree algorithm that i wrote a long time
ago.  i can't seem to find the newer one, its probably at work.  but
this one works just fine.  it returns the entire tree in array
DIR.ARR$.              Eric
 
 
 
'tree.bas    written by Eric Schonning   Fido 1:206/2512
'this routine is freely passed into the public domain
'for Power Basic users.  If you want to give me credit then
'thats ok, but I don't expect it.
'thanks go to Dave Navarro for help with the dta information
 
'this routine will create a complete tree listing for drive drv$
'using pb dir$ command and dta information
 
dim dynamic dir.arr$(2000)  'array to hold directory info from dir$
 
drv$="c:":drv$=ucase$(drv$)   'drive letter to get tree of
'you could also use command$ for this to use on command line
 
cls
print
print "Tree Listing for Drive "drv$
print
print drv$+"\"
td%=1  'total directories on drive, start at 1 for root dir
call get.disk.tree(drv$,td%)
'complete tree structure is still in dir.arr$(), so you could write it
'to a file here
print
print td%"Directories on Drive "drv$
'print drv$+"\"
'for i%=2 to td%
'  print dir.arr$(i%)
'next i%
'print td%"Directories on Drive "drv$
close
end
 
sub get.dta.addr(dtaseg%,dtaofs%) local
  'get disk transfer area address
  reg 1,&h2f00   'ah=2Fh
  call interrupt &h21
  dtaseg%=reg(9)
  dtaofs%=reg(2)
end sub
 
sub get.disk.tree(chkdir$,td%) local
  shared dir.arr$(),drv$
  'fa%=file attributes   tl%=total lines in dir
  'testdir$=directory to test
  fa%=0:tl%=0:chkdir$=ucase$(chkdir$):testdir$=""
  do
    incr tl%
    if tl%=1 then
      if chkdir$=drv$ then testdir$=drv$+"\*.*" else testdir$=chkdir$+"\*.
*"
      dir.arr$(td%+1)=dir$(testdir$,18)  'get hidden dirs too
    else
      dir.arr$(td%+1)=dir$
    end if
    if dir.arr$(td%+1)="" then exit loop
    call get.dta.addr(dtaseg%,dtaofs%)
    def seg=dtaseg%
    fa%=peek(dtaofs%+21)   'attribute for file located at offset+21
    def seg
    'test attribute for directory
    if (fa% and &b10000) then
      incr td%
      dir.arr$(td%)=chkdir$+"\"+dir.arr$(td%)
      print dir.arr$(td%)
      'call it again to check for sub-directories off of current dir
      call get.disk.tree(dir.arr$(td%),td%)
      'must set dir$ back to where we left off before recursive call
      for i%=1 to tl%
        if i%=1 then null$=dir$(testdir$,18) else null$=dir$
      next i%
      dir.arr$(td%+1)=" "  'so it won't exit out of loop prematurely
    end if
  loop while dir.arr$(td%+1)  ""
end sub
--- QM v1.00
---------------
* Origin: Creekside Manor (805) 484-8016 CdCom Support BBS (1:206/2512.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.