Page 1 of 1
find the program's path
Posted: Mon Jun 07, 2004 2:01 am
by Guest
ok, in qbasic, how can you find the path of the app running? like, you create a qb file and move it somewhere, and then open up the file and it tells you where you moved it and where it is. how can you do this?
Re: find the program's path
Posted: Mon Jun 07, 2004 7:37 pm
by Guest
There is a program, telbooks, which find out where it is
http://www.network54.com/Forum/message? ... 1056850889
I wrote it some time ago and now can't easily find out how it does it.
The big picture, though, is that if your program is HAPPY.BAS then if you called it via "QBasic /run HAPPY" then it is pretty easy to use SHELL DIR HAPPY.BAS.
But if you called it via "QBasic /run c:\temp\HAPPY" while you were in some other directory, then the human has to help. Of course, you could try to read the screen to find the exact command given. And, if that command were a BAT file, you could examine the BAT file, etc., etc.
There may be some trick that I don't know about. You could try also asking your question on The QBasic Forum
http://www.network54.com/Forum/13959
Mac
Re: find the program's path
Posted: Wed Jun 09, 2004 6:05 am
by Guest
Here's a quick shell that should work
SHELL "dir >mydir.fil"
OPEN "mydir.fil" FOR INPUT AS #1
DO
LINE INPUT #1, LL$
L% = INSTR(UCASE$(LL$), "DIRECTORY OF")
IF L% THEN
CurrDir$ = LTRIM$(RTRIM$(MID$(LL$, L% + 12)))
EXIT DO
END IF
LOOP WHILE NOT EOF(1)
CLOSE #1
PRINT CurrDir$
True, but wouldn't that only give CURDIR?
Posted: Wed Jun 09, 2004 6:46 am
by Guest
Your solution will give the directory where you were when you invoked QBasic.
If you are in c:\gab\fob
and you do
QBasic /run c:\moppy\snerd\MyProg
Then, rather than the desired result
c:\moppy\snerd
your program will simply give
c:\gab\fob
In VB there is an AppDir and a CurDir. He wants the AppDIR. That is tough.
Mac
Re: find the program's path
Posted: Wed Jun 09, 2004 3:36 pm
by Guest
Yes, I realized that right after i posted my reply.
Ah, so
Posted: Wed Jun 09, 2004 6:33 pm
by Guest
And I see how the telbooks program works.
First, it assumes it is stored in the CURDIR and is named "telbooks.bas". When I finds this is not true, it prompts the user to find itself.
Here is the good part: when it finally finds itself, it modifies the source code with the APPDIR and application name.
Thereafter, it runs without user intervention.
For example, you are in directory c:\xxxxx and you do
QBasic /run c:\abc\def\NEWNAME.BAS
First time, you get prompted and have to help the program find itself.
Thereafter, it just runs.
Of course, this assumes the program in in Source form, not EXE.
Mac