home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / fulldir.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-26  |  5.6 KB  |  170 lines

  1. '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  2. '  Msg#: 417                                          Date: 23 Apr 94  12:44:00
  3. '  From: Tom Cunha                                    Read: Yes    Replied: No 
  4. '    To: Chris Gauvin                                 Mark:                     
  5. '  Subj: Reading files from DIR
  6. '──────────────────────────────────────────────────────────────────────────────
  7. ' > I need some help to get this to work... I can't figure out what
  8. ' > the problem
  9. ' > is. My goal is to eventually read the files from a dir into an
  10. ' > array called
  11. ' > FILE$.
  12.  
  13. 'FULLDIR.BAS by Gaylon Hill
  14. '
  15. 'CALL FullDir(Dir$(), DirNum, FileDir, Path$, WildCard$)
  16. 'Dir$()     - is filled with the directory file names, size, date, & time.
  17. 'Dirnum     - returns the number of Dir$() (arrays).
  18. 'FileDir    - if FileDir = 1 then sub-directories names are returned, also.
  19. 'Path$      - if Path$= "" then the default path is used. Please note,
  20. '             if the Path$ is given then the wildcard will have to be
  21. '             given with the path name.
  22. '             Ex: Path$ = "\MAIN\QB\*.BAS" or Path$ = "A:\*.*"
  23. 'WildCard$  - the WildCard$ selects the type of file needed. Use ? or *
  24. '             to narrow the file selection. If WildCard$ = "" then the
  25. '             default is "*.*". This entry has NO EFFECT when the Path$
  26. '             is given.
  27.  
  28. TYPE FileFindBuf
  29.     DOS            AS STRING * 19
  30.     CreateTime     AS STRING * 1
  31.     Attributes     AS INTEGER
  32.     AccessTime     AS INTEGER
  33.     AccessDate     AS INTEGER
  34.     FileSize       AS LONG
  35.     FileName       AS STRING * 13
  36. END TYPE
  37.  
  38. TYPE Register
  39.     ax    AS INTEGER
  40.     bx    AS INTEGER
  41.     cx    AS INTEGER
  42.     dx    AS INTEGER
  43.     bp    AS INTEGER
  44.     si    AS INTEGER
  45.     di    AS INTEGER
  46.     flags AS INTEGER
  47.     ds    AS INTEGER
  48.     es    AS INTEGER
  49. END TYPE
  50.  
  51. DEFINT A-Z
  52. '
  53. SUB FullDir (Dir$(), DirNum, FileDir, path$, WildCard$)
  54.  
  55.     DIM inreg AS Register, outreg AS Register
  56.     DIM Buffer AS FileFindBuf
  57.  
  58.     DirNum = 0
  59.  
  60.     IF WildCard$ = "" THEN
  61.         WildCard$ = "*.*"
  62.     END IF
  63.  
  64.     IF path$ = "" THEN
  65.     '========================================================================
  66.     'Get Current Drive
  67.     '========================================================================
  68.  
  69.         inreg.ax = &H1900
  70.         CALL Interrupt(&H21, inreg, inreg)
  71.         Drive$ = CHR$(65 + inreg.ax MOD 256)
  72.  
  73.     '========================================================================
  74.     'Get Current Path
  75.     '========================================================================
  76.         DIM PathSize AS STRING * 64
  77.         inreg.ax = &H4700
  78.         inreg.dx = ASC(Drive$) - 64
  79.         inreg.ds = VARSEG(PathSize)
  80.         inreg.si = VARPTR(PathSize)
  81.         CALL InterruptX(&H21, inreg, inreg)
  82.         path$ = LEFT$(PathSize, INSTR(PathSize, CHR$(0)) - 1)
  83.         path$ = Drive$ + ":\" + path$ + "\" + WildCard$
  84.     END IF
  85.     '========================================================================
  86.     'Set the area where the file information will be stored
  87.     '========================================================================
  88.     inreg.ax = &H1A00
  89.     inreg.ds = VARSEG(Buffer)
  90.     inreg.dx = VARPTR(Buffer)
  91.     CALL Interrupt(&H21, inreg, outreg)
  92.  
  93.     '========================================================================
  94.     'Find the first file, if FirstFM=0 then continue.
  95.     '========================================================================
  96.     inreg.ax = &H4E00
  97.     inreg.cx = 62
  98.     NPath$ = path$ + CHR$(0)
  99.     inreg.dx = SADD(NPath$)
  100.     CALL Interrupt(&H21, inreg, outreg)
  101.     FirstFM = (outreg.ax AND &HF)
  102.  
  103.     '========================================================================
  104.     'Find the next file(s), if NextFM<>0 then exit.
  105.     '========================================================================
  106.     IF FirstFM = 0 THEN
  107.         GOSUB MakeFile
  108.         DO
  109.             inreg.ax = &H4F00
  110.             inreg.dx = SADD(NPath$)
  111.             CALL Interrupt(&H21, inreg, outreg)
  112.             NextFM = outreg.ax AND &HF
  113.             IF NextFM = 0 THEN
  114.                 GOSUB MakeFile
  115.             END IF
  116.         LOOP WHILE NextFM = 0
  117.     END IF
  118.     EXIT SUB
  119.  
  120. MakeFile:
  121.     IF LEFT$(Buffer.FileName, 1) = "." THEN
  122.         RETURN
  123.     END IF
  124.  
  125.     FSize$ = RIGHT$(SPACE$(8) + STR$(Buffer.FileSize), 8)
  126.  
  127.     BitT = Buffer.AccessTime
  128.     ahr = 0
  129.     IF BitT < 0 THEN BitT = 32767 + BitT: ahr = 16
  130.     hr = (BitT \ 2048)
  131.     mm = (BitT - (hr * 2048)) \ 32
  132.     hr = ahr + hr
  133.     FTime$ = RIGHT$("00" + LTRIM$(STR$(hr)), 2) + ":" + RIGHT$("00" +
  134. LTRIM$(STR$(mm)), 2)
  135.  
  136.     BitD = Buffer.AccessDate
  137.     yr = BitD \ 512
  138.     mo = (BitD - (yr * 512)) \ 32
  139.     da = BitD - (yr * 512) - (mo * 32)
  140.     FDate$ = RIGHT$("0" + LTRIM$(STR$(mo)), 2) + "-" + RIGHT$("0" +
  141. LTRIM$(STR$(da)), 2) + "-" + LTRIM$(STR$(80 + yr))
  142.  
  143.     x = INSTR(Buffer.FileName, ".")
  144.     IF x = 0 THEN
  145.         FileTemp$ = LEFT$(Buffer.FileName + STRING$(12, 32), 12)
  146.     ELSE
  147.         FileTemp$ = LEFT$(LEFT$(Buffer.FileName, x - 1) + SPACE$(12), 8) +
  148. MID$(Buffer.FileName, x, 4)
  149.     END IF
  150.  
  151.     IF Buffer.Attributes = 4096 AND FileDir = 1 THEN
  152.         FileTemp$ = MID$(Buffer.FileName, 1, 12)
  153.     END IF
  154.  
  155.     DirNum = DirNum + 1
  156.     Dir$(DirNum) = FileTemp$ + FSize$ + "  " + FDate$ + "  " + FTime$
  157.  
  158.     IF Buffer.Attributes = 4096 AND FileDir = 1 THEN
  159.         MID$(Dir$(DirNum), 13, 9) = "<dir>    "
  160.     END IF
  161.  
  162.     Buffer.Attributes = 0
  163.     Buffer.AccessTime = 0
  164.     Buffer.AccessDate = 0
  165.     Buffer.FileSize = 0
  166.     Buffer.FileName = STRING$(13, 32)
  167.     RETURN
  168.  
  169. END SUB
  170.