home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY4 / TTDIR1.ZIP / TTDIR105.BAS < prev    next >
BASIC Source File  |  1990-11-24  |  6KB  |  187 lines

  1. $COMPILE UNIT
  2. $INCLUDE "REGNAMES.INC"
  3.  
  4. '
  5. ' ┌─────────────────────────────────────────────────────────────────────┐
  6. ' │                                                                     │
  7. ' │ Function Name:  GetDirectory                                        │
  8. ' │ Date.........:  90/11/16                                            │
  9. ' │                                                                     │
  10. ' │ Description..:  Reads the directory specified by the user and       │
  11. ' │                 returns an array of the files found.                │
  12. ' │                                                                     │
  13. ' └─────────────────────────────────────────────────────────────────────┘
  14. '
  15. '   Modified.....:  90/11/23
  16. '
  17. '                   1.01 - Changed the return of the complete
  18. '                          directory in FileFound$ to the filename,
  19. '                          attribute, date and time to separate
  20. '                          fields.
  21. '
  22. '                   1.02 - Changed the calculation for the number of
  23. '                          files. I did a direct calc outside the loop
  24. '                          instead of incrementing a counter within
  25. '                          the loop.
  26. '
  27. '                   1.03 - Fixed the portion that calculated the file
  28. '                          size. I used the wrong type of 'peek'
  29. '                          function and the maximum size it returned
  30. '                          was 65,535.
  31. '
  32. '                   1.04 - Passed file string information in one
  33. '                          string and date/time information in one
  34. '                          array.
  35. '
  36. '                   1.05 - Moved the DOS call to get the DTA address.
  37. '                          The program only needs to find out the
  38. '                          address once!
  39. '
  40.  
  41. SUB GetDirectory(Path$, FileInfo$(), FIDate%(), FISize&(), NumFiles%) LOCAL PUBLIC
  42.  
  43. '  The parameters for the sub-routine are as follows:
  44. '
  45. '        Path$            - The file path
  46. '
  47. '
  48. '        FileInfo$(r,c)   - The files found.  A string array with up
  49. '                           to 'r' number of elements with 'c'
  50. '                           columns.  Column 1 is the file name.
  51. '                           Column 2 is the file extension and column
  52. '                           3 is the attributes of the file.
  53. '
  54. '
  55. '
  56. '        FIDate%(r,c)    - The Date and time for each file found. This
  57. '                          is a two dimensional array.  The number of
  58. '                          rows ('r') must be the same as for the
  59. '                          FileInfo$ field.  The number of columns
  60. '                          ('c') must be six (For Year, Month, Day,
  61. '                          Hour, Minute, Second)
  62. '
  63. '        FISize&(r)     -  The size in bytes of each file.
  64. '
  65. '        NumFiles%       - The number of files found in the directory
  66. '                          specified by PATH$
  67. '
  68. '
  69.  
  70. LOCAL A%
  71. LOCAL CDHiB%
  72. LOCAL CDLowB%
  73. LOCAL CDMidB%
  74. LOCAL CTHiB%
  75. LOCAL CTLowB%
  76. LOCAL CTMidB%
  77. LOCAL DTAAttr&
  78. LOCAL DTADate&
  79. LOCAL DTAOFS&
  80. LOCAL DTASEG&
  81. LOCAL DTASize&
  82. LOCAL DTATime&
  83. LOCAL FDate%
  84. LOCAL FF$
  85. LOCAL FTHour%
  86. LOCAL FTime%
  87. LOCAL LowB%
  88. LOCAL UpprB%
  89.  
  90. '
  91. ' Get the lower and upper bound for all of the arrays used.  I am assuming
  92. ' that all arrays are defined with the same lower and upper bound ranges.
  93. '
  94.  
  95.   LowB%  = LBOUND(FileInfo$(1))
  96.   UpprB% = UBOUND(FileInfo$(1))
  97.  
  98.   CDLowB%    = LBOUND(FIDate%(2))
  99.   CDMidB%    = CDLowB% + 1%
  100.   CDHiB%     = CDLowB% + 2%
  101.  
  102.   CTLowB%    = CDLowB% + 3%
  103.   CTMidB%    = CDMidB% + 3%
  104.   CTHiB%     = CDHiB%  + 3%
  105.  
  106.   FF$ = DIR$(Path$, 55%)
  107.  
  108. '
  109. '   Make a call to get the DTA on the file just read in.  I moved this code
  110. '   to outside the loop as I only have to get the address once!
  111. '
  112.   REG %AX, &H2F00
  113.   CALL INTERRUPT &H21
  114.  
  115.   DTASEG& = REG(%ES)
  116.   DTAOFS& = REG(%BX)
  117.   DTAAttr& = DTAOFS& + 21
  118.   DTASize& = DTAOFS& + 26
  119.   DTADate& = DTAOFS& + 24
  120.   DTATIME& = DTAOFS& + 22
  121.  
  122.   DO WHILE (LEN(FF$) > 0%  AND  LowB% <= UpprB%)
  123.  
  124.     DEF SEG = DTASEG&
  125.       A%             =  PEEK(DTAAttr&)
  126.       FISize&(LowB%) = PEEKL(DTASize&)
  127.       FDate%         = PEEKI(DTADate&)
  128.       FTime%         = PEEKI(DTATime&)
  129.     DEF SEG
  130.  
  131.     FileInfo$(LowB%, 1) = FF$
  132.     FileInfo$(LowB%, 2) = " "
  133.     X% = INSTR(FF$, ".")
  134.     IF X% > 0 THEN
  135.       FileInfo$(LowB%, 1) = MID$(FF$, 1, X%-1)
  136.       FileInfo$(LowB%, 2) = MID$(FF$, X%+1)
  137.     END IF
  138.  
  139.     FileInfo$(LowB%, 3%) = "....."
  140.     IF (A% AND 32%) THEN
  141.       MID$(FileInfo$(LowB%, 3%), 4, 1) = "A"
  142.     END IF
  143.  
  144.     IF (A% AND 16%) THEN
  145.       MID$(FileInfo$(LowB%, 3%), 5, 1) = "D"
  146.     END IF
  147.  
  148.     IF (A% AND 4%) THEN
  149.       MID$(FileInfo$(LowB%, 3%), 1, 1) = "S"
  150.     END IF
  151.  
  152.     IF (A% AND 2%) THEN
  153.       MID$(FileInfo$(LowB%, 3%), 2, 1) = "H"
  154.     END IF
  155.  
  156.     IF (A% AND 1%) THEN
  157.       MID$(FileInfo$(LowB%, 3%), 3, 1) = "R"
  158.     END IF
  159.  
  160.     FIDate%(LowB%, CTLowB%) = FTime% \ 2048%           ' Hours
  161.     IF FIDate%(LowB%, CTLowB%) < 0% THEN
  162.       INCR FIDate%(LowB%, CTLowB%), 31%                ' Fix for some P.M. hours
  163.     END IF
  164.  
  165.     FIDate%(LowB%, CTMidB%) = (FTime% AND 2047%) \ 32% ' Minutes
  166.     FIDate%(LowB%, CTHiB%)  = FTime% AND 31%           ' Seconds
  167.  
  168.     FIDate%(LowB%, CDLowB%) = (FDate% \ 512%) + 80%    ' Year
  169.     FIDate%(LowB%, CDMidB%) = (Fdate% AND 511%) \ 32%  ' Month
  170.     FIDate%(LowB%, CDHiB%)  = FDate% AND 31%           ' Day
  171.  
  172.     INCR LowB%, 1
  173.  
  174. '
  175. '   If not the last entry in the array read another directory entry.
  176. '
  177.  
  178.     IF LowB% <= UpprB% THEN
  179.       FF$ = DIR$
  180.     END IF
  181.   WEND
  182.  
  183.   NumFiles% = LowB% - LBOUND(FileInfo$(1))            ' Calculate number of
  184.                                                       ' files found.
  185.  
  186. END SUB
  187.