home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / WINER.ZIP / CHAP11-7.BAS < prev    next >
BASIC Source File  |  1992-05-13  |  1KB  |  55 lines

  1. '*********** CHAP11-7.BAS - demonstrates reading the current directory
  2.  
  3. 'Copyright (c) 1992 Ethan Winer
  4.  
  5. DEFINT A-Z
  6. '$INCLUDE: 'REGTYPE.BI'
  7.  
  8. DIM Registers AS RegType
  9.  
  10. DEF FnGetDir$ (Drive$)
  11.   STATIC Temp$, Drive, Zero     'local variables
  12.  
  13.   IF LEN(Drive$) THEN           'did they pass a drive?
  14.     Drive = ASC(UCASE$(Drive$)) - 64
  15.   ELSE
  16.     Drive = 0
  17.   END IF
  18.  
  19.   Temp$ = SPACE$(65)            'DOS stores the name here
  20.  
  21.   Registers.AX = &H4700         'get directory service
  22.   Registers.DX = Drive          'the drive goes in DL
  23.   Registers.SI = SADD(Temp$)    'show DOS where Temp$ is
  24.   Registers.DS = SSEG(Temp$)    'use this with BASIC PDS
  25.  'Registers.DS = -1             'use this with QuickBASIC
  26.  
  27.   CALL DOSInt(Registers)        'call DOS
  28.  
  29.   IF Registers.Flags AND 1 THEN 'must be an invalid drive
  30.     FnGetDir$ = ""
  31.   ELSE
  32.     Zero = INSTR(Temp$, CHR$(0))    'find the zero byte
  33.     FnGetDir$ = "\" + LEFT$(Temp$, Zero)
  34.   END IF
  35. END DEF
  36.  
  37.  
  38. PRINT "Which drive? ";
  39. DO
  40.   Drive$ = INKEY$
  41. LOOP UNTIL LEN(Drive$)
  42. PRINT
  43.  
  44.  
  45. Cur$ = FnGetDir$(Drive$)
  46. IF LEN(Cur$) THEN
  47.   PRINT "The current directory is ";
  48.   PRINT Drive$; ":"; FnGetDir$(Drive$)
  49. ELSE
  50.   PRINT "Invalid drive"
  51. END IF
  52.  
  53. PRINT "The current directory for the default drive is ";
  54. PRINT FnGetDir$("")
  55.