home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 9.8. A function that creates a variable structure array.
- Author: Craig Yellick
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
-
- #include "DIRECTRY.CH"
-
- function LoadDir(path)
- /*
- Return array containing entire directory structure
- of drive volume. This function uses a recursive call
- to itself. You do not need to specify the path unless
- you want to load only a subset of the drive volume.
-
- */
- local i, name, d_, r_ := {}
-
- if path = nil
- path := "\"
- endif
-
- // Load contents of the specified directory path,
- // including any subdirectory entries that might be there.
- d_ := directory(path +"*.*", "D")
-
- // Loop once for each entry in directory.
- for i := 1 to len(d_)
- name := d_[i, F_NAME]
-
- // If the file attribute indicates this
- // is a subdirectory entry, special handling is needed.
- if d_[i, F_ATTR] = "D"
-
- // Skip the "." and ".." entries.
- // (The $ operator means "contained in")
- if .not. (name $ "..")
-
- // Add the subdirectory name to the array
- // and call the directory loader function to
- // return the array of file names.
- aadd(r_, {name, LoadDir(path +name +"\")})
- endif
-
- // If the file isn't a subdirectory name,
- // add it to the array of file names.
- else
- aadd(r_, name)
- endif
- next i
-
- return r_
-
- // end of file CHP0908.PRG
-