home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP09.EXE / CHP0908.PRG < prev    next >
Encoding:
Text File  |  1991-06-01  |  1.6 KB  |  60 lines

  1. /*
  2.    Listing 9.8. A function that creates a variable structure array.
  3.    Author: Craig Yellick
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11.  
  12. #include "DIRECTRY.CH"
  13.  
  14. function LoadDir(path)
  15. /*
  16.    Return array containing entire directory structure
  17.    of drive volume. This function uses a recursive call
  18.    to itself. You do not need to specify the path unless
  19.    you want to load only a subset of the drive volume.
  20.  
  21. */
  22. local i, name, d_, r_ := {}
  23.  
  24.   if path = nil
  25.     path := "\"
  26.   endif
  27.  
  28.   //  Load contents of the specified directory path,
  29.   //  including any subdirectory entries that might be there.
  30.   d_ := directory(path +"*.*", "D")
  31.  
  32.   //  Loop once for each entry in directory.
  33.   for i := 1 to len(d_)
  34.     name := d_[i, F_NAME]
  35.  
  36.     //  If the file attribute indicates this
  37.     //  is a subdirectory entry, special handling is needed.
  38.     if d_[i, F_ATTR] = "D"
  39.  
  40.       //  Skip the "." and ".." entries.
  41.       //  (The $ operator means "contained in")
  42.       if .not. (name $ "..")
  43.  
  44.         //  Add the subdirectory name to the array
  45.         //  and call the directory loader function to
  46.         //  return the array of file names.
  47.         aadd(r_, {name, LoadDir(path +name +"\")})
  48.       endif
  49.  
  50.     //  If the file isn't a subdirectory name,
  51.     //  add it to the array of file names.
  52.     else
  53.       aadd(r_, name)
  54.     endif
  55.   next i
  56.  
  57. return r_
  58.  
  59. // end of file CHP0908.PRG
  60.