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