home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l180 / 2.ddi / QBTREE.BAS < prev    next >
Encoding:
BASIC Source File  |  1989-02-07  |  6.4 KB  |  182 lines

  1.   ' ************************************************
  2.   ' **  Name:          QBTREE                     **
  3.   ' **  Type:          Program                    **
  4.   ' **  Module:        QBTREE.BAS                 **
  5.   ' **  Language:      Microsoft QuickBASIC 4.00  **
  6.   ' ************************************************
  7.   '
  8.   ' This program creates a list of directories and
  9.   ' subdirectories, and all files in them.  If no
  10.   ' command line path is given, the search
  11.   ' begins with the current directory.
  12.   '
  13.   ' USAGE:          QBTREE [path]
  14.   ' REQUIREMENTS:   MIXED.QLB/.LIB
  15.   ' .MAK FILE:      QBTREE.BAS
  16.   '                 FILEINFO.BAS
  17.   ' PARAMETERS:     path       Path for starting directory search
  18.   ' VARIABLES:      path$      Path string, from the command line, or set
  19.   '                            to "*.*"
  20.   '                 indent%    Indention amount for printing
  21.   
  22.   
  23.     TYPE RegTypeX
  24.         ax    AS INTEGER
  25.         bx    AS INTEGER
  26.         cx    AS INTEGER
  27.         dx    AS INTEGER
  28.         bp    AS INTEGER
  29.         si    AS INTEGER
  30.         di    AS INTEGER
  31.         flags AS INTEGER
  32.         ds    AS INTEGER
  33.         es    AS INTEGER
  34.     END TYPE
  35.   
  36.     TYPE FileDataType
  37.         finame    AS STRING * 12
  38.         year      AS INTEGER
  39.         month     AS INTEGER
  40.         day       AS INTEGER
  41.         hour      AS INTEGER
  42.         minute    AS INTEGER
  43.         second    AS INTEGER
  44.         attribute AS INTEGER
  45.         size      AS LONG
  46.     END TYPE
  47.   
  48.   ' Subprograms
  49.     DECLARE SUB INTERRUPTX (intnum%, inreg AS RegTypeX, outreg AS RegTypeX)
  50.     DECLARE SUB FindFirstFile (path$, dta$, result%)
  51.     DECLARE SUB FindNextFile (dta$, result%)
  52.     DECLARE SUB GetFileData (dta$, file AS FileDataType)
  53.     DECLARE SUB FileTreeSearch (path$, indent%)
  54.   
  55.   ' Create structure for deciphering the DTA file search results
  56.     DIM file AS FileDataType
  57.   
  58.   ' Get the command line path for starting the file search
  59.     path$ = COMMAND$
  60.   
  61.   ' If no path was given, then use "*.*" to search the current directory
  62.     IF path$ = "" THEN
  63.         path$ = "*.*"
  64.     END IF
  65.  
  66.   ' If only a drive was given, then add "*.*"
  67.     IF LEN(path$) = 2 AND RIGHT$(path$, 1) = ":" THEN
  68.         path$ = path$ + "*.*"
  69.     END IF
  70.   
  71.   ' Adjust the given path if necessary
  72.     IF INSTR(path$, "*") = 0 AND INSTR(path$, "?") = 0 THEN
  73.         FindFirstFile path$, dta$, result%
  74.         IF result% = 0 OR RIGHT$(path$, 1) = "\" THEN
  75.             IF RIGHT$(path$, 1) <> "\" THEN
  76.                 path$ = path$ + "\"
  77.             END IF
  78.             path$ = path$ + "*.*"
  79.         END IF
  80.     END IF
  81.   
  82.   ' Start with a clean slate
  83.     CLS
  84.   
  85.   ' Call the recursive search subprogram
  86.     FileTreeSearch path$, indent%
  87.   
  88.   ' That's all there is to it
  89.     END
  90.   
  91.  
  92.   ' ************************************************
  93.   ' **  Name:          FileTreeSearch             **
  94.   ' **  Type:          Subprogram                 **
  95.   ' **  Module:        QBTREE.BAS                 **
  96.   ' **  Language:      Microsoft QuickBASIC 4.00  **
  97.   ' ************************************************
  98.   '
  99.   ' Directory searching and listing subprogram for
  100.   ' the QBTREE program.  (recursive)
  101.   '
  102.   ' EXAMPLE OF USE:  FileTreeSearch path$, indent%
  103.   ' PARAMETERS:      path$      Path for search of files
  104.   '                  indent%    Level of indention, function of recursion
  105.   '                             level
  106.   ' VARIABLES:       file       Structure of type FileDataType
  107.   '                  path$      Path for search of files
  108.   '                  dta$       Disk Transfer Area buffer string
  109.   '                  result%    Returned result code from FindFirstFile or
  110.   '                             FindNextFile
  111.   '                  newPath$   Path with added subdirectory for recursive
  112.   '                             search
  113.   ' MODULE LEVEL
  114.   '   DECLARATIONS: TYPE FileDataType
  115.   '                     finame    AS STRING * 12
  116.   '                     year      AS INTEGER
  117.   '                     month     AS INTEGER
  118.   '                     day       AS INTEGER
  119.   '                     hour      AS INTEGER
  120.   '                     minute    AS INTEGER
  121.   '                     second    AS INTEGER
  122.   '                     attribute AS INTEGER
  123.   '                     size      AS LONG
  124.   '                  END TYPE
  125.   '
  126.   '                  DECLARE SUB FindFirstFile (path$, dta$, result%)
  127.   '                  DECLARE SUB FindNextFile (dta$, result%)
  128.   '                  DECLARE SUB GetFileData (dta$, file AS FileDataType)
  129.   '                  DECLARE SUB FileTreeSearch (path$, indent%)
  130.   '
  131.     SUB FileTreeSearch (path$, indent%)
  132.       
  133.       ' Create structure for deciphering the DTA file search results
  134.         DIM file AS FileDataType
  135.       
  136.       ' Find the first file given the current search path
  137.         FindFirstFile path$, dta$, result%
  138.       
  139.       ' Search through the directory for all files
  140.         DO UNTIL result%
  141.           
  142.           ' Unpack the Disk Transfer Area for file information
  143.             GetFileData dta$, file
  144.           
  145.           ' Skip the "." and ".." files
  146.             IF LEFT$(file.finame, 1) <> "." THEN
  147.               
  148.               ' Print the filename, indented to show tree structure
  149.                 PRINT SPACE$(indent% * 4); file.finame;
  150.               
  151.               ' Print any other desired file information here
  152.                 PRINT TAB(50); file.size;
  153.                 PRINT TAB(58); file.attribute
  154.               
  155.               ' If we found a directory, then recursively search through it
  156.                 IF file.attribute AND &H10 THEN
  157.                   
  158.                   ' Modify path$ to add this new directory to the search path
  159.                     newPath$ = path$
  160.                     IF INSTR(newPath$, "\") = 0 THEN
  161.                         newPath$ = "\" + newPath$
  162.                     END IF
  163.                     DO WHILE RIGHT$(newPath$, 1) <> "\"
  164.                         newPath$ = LEFT$(newPath$, LEN(newPath$) - 1)
  165.                     LOOP
  166.                     newPath$ = newPath$ + file.finame + "\*.*"
  167.                   
  168.                   ' Example of recursion here
  169.                     FileTreeSearch newPath$, indent% + 1
  170.                   
  171.                 END IF
  172.               
  173.             END IF
  174.           
  175.           ' Try to find the next file in this directory
  176.             FindNextFile dta$, result%
  177.           
  178.         LOOP
  179.       
  180.     END SUB
  181.  
  182.