his book shows how to recursively scan a directory tree. Since the "DIR$" command cannot
be nested a simple recursive call to the scanning function is not possible. So it is a
good idea to store all found sub-directories in an array and process them seperately after
the current directory has been entirely scanned.
Scanning a directory tree
T
his program expects a starting directory (path) as command line argument. Then it will
show the number of files and directories in that directory and all sub-directories.
'Author : Daniel, Master Sourcerer at Kitana's Cas...
'Last change: July 27, 2004
'Email : sourcerer@kitana.org
'Recursively scans a directory tree
#DIM ALL
%MAXDIRS = 256
'Scan a directory and all of its sub-directories
SUB SCANDIR(P$)
LOCAL F$
LOCAL I&
LOCAL NFILES&,NDIRS&
LOCAL D$()
DIM D$(%MAXDIRS-1)
'scan directory
F$=DIR$(P$+"*.*",23)
WHILE F$<>""
IF (GETATTR(P$+F$) AND 16)=0 THEN 'a file
NFILES&=NFILES&+1
ELSE 'a directory
IF F$<>"." AND F$<>".."THEN 'ignore up-director...
IF NDIRS&<%MAXDIRS THEN
D$(NDIRS&)=F$
NDIRS&=NDIRS&+1
END IF