QB45 - Path to my app? 
Author Message
 QB45 - Path to my app?

Hello,

I'm using QB4.5 and I need to know what is the current directory (path)
where my program (.exe) is running.  Something similar to App.Path in
Visual Basic.  

Is there any command or how can I do this?

Thanks for any help,

Alejandro




Sun, 26 Nov 2000 03:00:00 GMT  
 QB45 - Path to my app?

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



Sun, 26 Nov 2000 03:00:00 GMT  
 QB45 - Path to my app?

Quote:
> I'm using QB4.5 and I need to know what is the current directory (path)
> where my program (.exe) is running.  Something similar to App.Path in
> visual Basic.  
> Is there any command or how can I do this?

It's a bit messy, but you can use code like;

SHELL("CD > c:\a.txt")
OPEN "C:\a.txt" FOR INPUT AS #1
LINE INPUT #1,PA$
CLOSE
KILL "C:\a.txt"      
END

Then PA$ will have the current directory, e.g. c:\games (without the end >)
Trouble is, if your app is in the path, or called from a batch file,
then the current directory
will not definitely be the directory your program is in.

Simon.



Sun, 26 Nov 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Paths and App.Path

2. using application path (app.path)

3. App.Path only returning short path name - Why?

4. app.path only returns short path name

5. Help: App.Path returns 8.3 path in VB4/Win95

6. PATH-APP AND MDB-PATH

7. app-path and mdb-path

8. App.Path returns "short" path name

9. Changing Long Paths to Short Paths in a 16-bit App

10. URGENT: app.path

11. App.path

12. Using app.path

 

 
Powered by phpBB® Forum Software