I wrote some code to do this a while back:
[syntax="QBasic"]
' A program to get the current directory and store it in a string.
' The main function is GetCurDir$
'
DECLARE FUNCTION GetCurDir$ ()
CLS
PRINT "Current directory: " + GetCurDir$
FUNCTION GetCurDir$
'
' GetCurDir$
' Coded by shiftLynx (Chris Davies) [12th Aug 2004]
' c.g.davies@gmail.com
'
' Create a string to store our assembly code in
DIM asmcode AS STRING * 27
' and a string to store the output from the asm code
DIM currentdir AS STRING * 512
' Get the segment and offset of the currentdir string
cdseg% = VARSEG(currentdir)
cdoff% = VARPTR(currentdir)
' Get the low and high bytes of cdseg%
cdsegb1% = cdseg% AND &HFF
cdsegb2% = (cdseg% \ &H100) AND &HFF
' Get the low and high bytes of cdoff%
cdoffb1% = cdoff% AND &HFF
cdoffb2% = (cdoff% \ &H100) AND &HFF
' First we need to get the current drive with this code...
'
'
' PUSHAD
' MOV AH, 0x19
' INT 0x21
' ADD AL, 0x41
' MOV BX, [cdseg]
' MOV ES, BX
' MOV DI, [cdoff]
' MOV [ES
I], AL
' POPAD
' RETF
'
asmcode = CHR$(&H66) + CHR$(&H60) + CHR$(&HB4) + CHR$(&H19) + CHR$(&HCD) + CHR$(&H21) + CHR$(&H4) + CHR$(&H41) + CHR$(&HBB) + CHR$(cdsegb1%) + CHR$(cdsegb2%) + CHR$(&H8E) + CHR$(&HC3) + CHR$(&HBF) + CHR$(cdoffb1%) + CHR$(cdoffb2%) + CHR$(&H26) + _
CHR$(&H88) + CHR$(&H5) + CHR$(&H66) + CHR$(&H61) + CHR$(&HCB)
' Execute the code
DEF SEG = VARSEG(asmcode)
CALL ABSOLUTE(VARPTR(asmcode))
DEF SEG
' Now we have the drive letter - keep track of it
retval$ = MID$(currentdir, 1, 1) + ":\"
' Next we need the current directory...
'
' PUSHAD
' MOV AH, 0x47
' XOR DL, DL
' INT 0x21
' MOV AX, [cdseg]
' MOV ES, AX
' MOV DI, [cdoff]
' nextbyte:
' MOVSB
' MOV AL, [ES:SI]
' TEST AL, AL
' JNZ nextbyte
' POPAD
' RETF
'
asmcode = CHR$(&H66) + CHR$(&H60) + CHR$(&HB4) + CHR$(&H47) + CHR$(&H30) + CHR$(&HD2) + CHR$(&HCD) + CHR$(&H21) + CHR$(&HB8) + CHR$(cdsegb1%) + CHR$(cdsegb2%) + CHR$(&H8E) + CHR$(&HC0) + CHR$(&HBF) + CHR$(cdoffb1%) + CHR$(cdoffb2%) + CHR$(&HA4) _
+ CHR$(&H26) + CHR$(&H8A) + CHR$(&H4) + CHR$(&H84) + CHR$(&HC0) + CHR$(&H75) + CHR$(&HF8) + CHR$(&H66) + CHR$(&H61) + CHR$(&HCB)
' Call the assembly code
DEF SEG = VARSEG(asmcode)
CALL ABSOLUTE(VARPTR(asmcode))
DEF SEG
' Find out how many characters currentdir has
numchars% = 0
FOR i% = 1 TO LEN(currentdir)
IF MID$(currentdir, i%, 1) = CHR$(0) THEN EXIT FOR
numchars% = numchars% + 1
NEXT i%
' Append the current directory to the drive letter
retval$ = retval$ + MID$(currentdir, 1, numchars%)
' Set the return value
GetCurDir$ = retval$
END FUNCTION
[/syntax]