home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12334.ZIP / GETDIR.BAS < prev    next >
BASIC Source File  |  1989-03-23  |  1KB  |  33 lines

  1. '***** GetDir.Bas - BASIC function that returns the current directory
  2.  
  3. 'syntax: Directory$ = GetDir$(Drive$)
  4. ' where: Drive$ is "A", "C", etc, or a null string meaning 
  5. '        the current drive
  6.  
  7. DEFINT A-Z
  8. DECLARE FUNCTION DosQCurDir%(BYVAL Drive, BYVAL StrSeg, _
  9.                  BYVAL StrAdr, SEG Length)
  10.  
  11.  
  12. FUNCTION GetDir$(Drive$)
  13.  
  14.    IF LEN(Drive$) THEN          'see if a drive letter was specified
  15.       DriveNum = ASC(UCASE$(Drive$)) - ASC("A") + 1 'convert to a drive number
  16.    ELSE
  17.       DriveNum = 0         'else, tell OS/2 to use the current drive
  18.    END IF
  19.  
  20.    BufLen = 64             'define the buffer's length
  21.    Path$ = SPACE$(BufLen)  'create a buffer to receive the directory
  22.                            'invoke the function
  23.    ErrorCode = DosQCurDir%(DriveNum, VARSEG(Path$), SADD(Path$), _
  24.                           BufLen)
  25.  
  26.    IF ErrorCode THEN      'see if there was an error
  27.       GetDir$ = ""       'return null string to indicate the error
  28.    ELSE                  'otherwise return what precedes the CHR$(0)
  29.       GetDir$ = "\" + LEFT$(Path$, INSTR(Path$, CHR$(0)) - 1)
  30.    END IF
  31.  
  32. END FUNCTION
  33.