home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / nvdc87 / tbdoscal / getdir.bas < prev   
BASIC Source File  |  1987-06-22  |  2KB  |  46 lines

  1. '*** GetDir.Bas - returns the current directory for a specified drive
  2.  
  3. CLS
  4. LINE INPUT "Which drive? ", D$
  5. CALL GetDir(D$, Directory$)
  6. PRINT "The current directory on drive "  D$  " is \"  Directory$
  7. END
  8.  
  9.  
  10. SUB GetDir(Drive$, Dir$) STATIC
  11.  
  12.     LOCAL Drive, Descriptor!, Address!
  13.  
  14.     Dir$ = SPACE$(64)                   'make room for directory name
  15.  
  16.     IF Drive$ = "" THEN                 'a drive wasn't specified, so
  17.        Drive = 0                        '  use the default drive
  18.     ELSE
  19.        Drive = ASC(UCASE$(Drive$)) - 64 'adjust so "A"=1, "B"=2, etc.
  20.     END IF
  21.  
  22.     DEF SEG = VARSEG(Dir$)              'find Dir$ descriptor address
  23.     Descriptor! = VARPTR(Dir$)
  24.     Address! = PEEK(Descriptor! + 2) + 256! * PEEK(Descriptor! + 3)
  25.  
  26.     DEF SEG                             'find string data segment at
  27.     REG %DS, PEEK(0) + 256! * PEEK(1)   'address 0, and put it in DS
  28.     REG %SI, Address!                   'offset within segment in SI
  29.     REG %DX, Drive                      'specify drive in DL
  30.     REG %AX, &H4700                     'specify service &H47 in AH
  31.  
  32.     CALL INTERRUPT &H21                 'call DOS
  33.  
  34.     IF Dir$ = SPACE$(64) THEN           'error - indicate this to the
  35.        Dir$ = "Error"                   '  caller with error message
  36.        EXIT SUB
  37.     END IF
  38.  
  39.     'keep only the name portion; DOS marks end with a CHR$(0)
  40.     Dir$ = LEFT$(Dir$, INSTR(Dir$, CHR$(0))-1)
  41.  
  42. END SUB
  43.  
  44. $INCLUDE "RegNames.Inc"                 'this file defines registers,
  45.                                         '  and is on the Turbo disk
  46.