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

  1. $COMPILE UNIT
  2. $INCLUDE "REGNAMES.INC"
  3.  
  4. '
  5. ' ┌─────────────────────────────────────────────────────────────────────┐
  6. ' │                                                                     │
  7. ' │ Function Name:  GetDir                                              │
  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. ' Original Code.  Kept to illustrate the difference between the first 'draft'
  16. ' of the code and the current version.
  17. '
  18. SUB GetDir100(Path$, FilesFound$(), NumFiles%) LOCAL PUBLIC
  19.  
  20. LOCAL A%
  21. LOCAL Att$
  22. LOCAL DTAOFS&
  23. LOCAL DTASEG&
  24. LOCAL FD$
  25. LOCAL FDate%
  26. LOCAL FSize&
  27. LOCAL FT$
  28. LOCAL FTHour%
  29. LOCAL FTime%
  30. LOCAL LowB%
  31. LOCAL UFn2$
  32. LOCAL UpprB%
  33. LOCAL X%
  34.  
  35.  
  36. '
  37. ' Get the lower bound and upper bound of the array for the directory.
  38. '
  39.  
  40.   LowB%  = LBOUND(FilesFound$(1))
  41.   UpprB% = UBOUND(FilesFound$(1))
  42.  
  43.   NumFiles%   = 0
  44.  
  45.   FilesFound$(LowB%) = DIR$(Path$,55)
  46.  
  47.   DO WHILE (LEN(FilesFound$(LowB%)) > 0  AND  LowB% <= UpprB%)
  48.     INCR NumFiles%, 1
  49.  
  50. '
  51. '   Make a call to get the DTA on the file just read in.
  52. '
  53.     REG %AX, &H2F00
  54.     CALL INTERRUPT &H21
  55.  
  56.     DTASEG& = REG(%ES)
  57.     DTAOFS& = REG(%BX)
  58.  
  59.     DEF SEG = DTASEG&
  60.     A%     = PEEK(DTAOFS&+21)                                                         ' Attributes
  61.     FSize& = (PEEK(DTAOFS&+27) * 256) + PEEK(DTAOFS&+26)   ' Size
  62.     FDate% = PEEKI(DTAOFS&+24)                             ' Date
  63.     FTime% = PEEKI(DTAOFS&+22)                             ' Time
  64.     DEF SEG
  65.  
  66. '
  67. '   Convert the number into a string:  Location 1 = System
  68. '                                               2 = Hidden
  69. '                                               3 = Read only
  70. '                                               4 = Archive
  71. '                                               5 = Directory Entry
  72. '                                               6 = Blank for padding
  73.  
  74.     Att$ = "..... "
  75.     IF (A% AND 32%) THEN
  76.       MID$(Att$, 4, 1) = "A"
  77.     END IF
  78.  
  79.     IF (A% AND 16%) THEN
  80.       MID$(Att$, 5, 1) = "D"
  81.     END IF
  82.  
  83.     IF (A% AND 4%) THEN
  84.       MID$(Att$, 1, 1) = "S"
  85.     END IF
  86.  
  87.     IF (A% AND 2%) THEN
  88.       MID$(Att$, 2, 1) = "H"
  89.     END IF
  90.  
  91.     IF (A% AND 1%) THEN
  92.       MID$(Att$, 3, 1) = "R"
  93.     END IF
  94.  
  95. '
  96. ' Reformat the file name into a string 13 characters in length.  Separate the
  97. ' file name from the extension.  The file name is the right hand most portion
  98. ' of the string.  The extension is the left most portion of the string.  The
  99. ' 13th character is a blank for padding.
  100. '
  101.  
  102.     UFn2$ = SPACE$(13)
  103.     IF (FilesFound$(LowB%) = ".")  OR  (FilesFound$(LowB%) = "..")  THEN
  104.       MID$(UFn2$, 1, LEN(FilesFound$(LowB%))) = FilesFound$(LowB%)
  105.     ELSE
  106.       X% = INSTR(FilesFound$(LowB%), ".")
  107.       IF X% > 0 THEN
  108.         MID$(UFn2$,  1, LEN(MID$(FilesFound$(LowB%), 1, X%-1))) = MID$(FilesFound$(LowB%), 1, X%-1)
  109.         MID$(UFn2$, 10, LEN(MID$(FilesFound$(LowB%), X%+1))) = MID$(FilesFound$(LowB%), X%+1)
  110.       ELSE
  111.         MID$(UFn2$,  1, LEN(FilesFound$(LowB%))) = FilesFound$(LowB%)
  112.       END IF
  113.     END IF
  114.  
  115. '
  116. '   Convert the File time into a string.
  117. '
  118.     FTHour% = FTime% \ 2048%
  119.     IF FTHour% < 0 THEN
  120.       INCR FTHour%, 32%                  ' Fix for some P.M. hours
  121.     END IF
  122.  
  123.     FT$ = USING$("##", FTHour%) + ":" + USING$("##", (FTime% AND 2047%) \ 32%) + ":" + USING$("##", FTime% AND 31%)
  124.     REPLACE ANY " " WITH "0" IN FT$
  125.  
  126. '
  127. '   Convert the file date into a string.
  128. '
  129.  
  130.     FD$ = USING$("##", (FDate% \ 512) + 80%) + "/" + USING$("##", (FDate% AND 511%) \ 32%) + "/" + USING$("##", FDate% AND 31%)
  131.     REPLACE ANY " " WITH "0" IN FD$
  132.  
  133.     FilesFound$(LowB%) = UFn2$ + Att$ + USING$("######## ", FSize&) + FT$ + " "+ FD$
  134.  
  135.     INCR LowB%, 1
  136.  
  137. '
  138. '   If not the last entry in the array read another directory entry.
  139. '
  140.  
  141.     IF LowB% <= UpprB% THEN
  142.       FilesFound$(LowB%) = DIR$
  143.     END IF
  144.   WEND
  145.  
  146. END SUB
  147.