AC>I'm using QB4.5 and I need to know what is the current directory
(path)
AC>where my program (.exe) is running. Something similar to App.Path in
AC>visual Basic.
AC>Is there any command or how can I do this?
Thanks to Robert Fortune who sent me a routine to obtain the current
path; I modified it a little bit to obtain also the path without the
.exe name
Invoke QB from the DOS command line like this:
QB THEPATH.BAS /L
' ------------ CUT HERE --------------------------- CUT HERE
REM THEPATH.BAS
DECLARE FUNCTION CurrentProg$ ()
DECLARE FUNCTION CurrentPath$ ()
'$INCLUDE: 'QB.BI'
DIM SHARED Register AS RegType
WhereIsIt$ = CurrentProg$
RealPath$ = CurrentPath$
PRINT "The current program is: "; WhereIsIt$
PRINT "The current directory is: "; RealPath$
END ' The End (of main program)
FUNCTION CurrentProg$
' Returns Full Drive/Path of Currently Running Program
Register.Ax = 25088 ' Interrupt to Find PSP
Interrupt &H21, Register, Register ' Call the Interrupt
DEF SEG = Register.Bx ' Segment of the PSP
EnvLo = PEEK(&H2C) ' The Pointers from the PSP to our copy of
the
EnvHi = PEEK(&H2D) ' DOS Environment
DEF SEG = EnvLo + (EnvHi * 256) ' Segment of DOS Environment
X = 0 ' Loop thru undeeded PSP Info, Jumping from
DO UNTIL PEEK(X) = 0 ' Null Byte, to Null Byte.
DO UNTIL PEEK(X) = 0
X = X + 1
LOOP
X = X + 1
LOOP
X = X + 3
' We Made it! Now read Ascii values of the String till we hit a
NULL.
DO UNTIL PEEK(X) = 0
PName$ = PName$ + CHR$(PEEK(X))
X = X + 1
LOOP
CurrentProg$ = PName$
END FUNCTION
FUNCTION CurrentPath$
' Returns Full Drive/Path of Currently Running Program
' To be used after CurrentProg$
DIM LenProg AS INTEGER
DIM slash AS INTEGER
WhereIsIt$ = CurrentProg$
LenProg = LEN(WhereIsIt$)
'Find last sub-directory
slash = INSTR(WhereIsIt$, "\")
WHILE INSTR(slash + 1, WhereIsIt$, "\") > 0
slash = INSTR(slash + 1, WhereIsIt$, "\")
WEND
CurrentPath$ = LEFT$(WhereIsIt$, slash)
END FUNCTION
' ------------ CUT HERE --------------------------- CUT HERE
I got this from the newsgroup where I *think* Brian M. posted it. I've
modified it slightly and made it a little easier to use with QB.
- Robert Fortune