Qbasicnews.com

Full Version: Displaying name of current dir paths using QB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
God - this is dogging me!
I have a program that loads files from set directory paths (i.e C:\QB\Games\file.txt)
This works well and good until I compile it and move the EXE file to a different directory. I can understand why this happens but I cannot figure a way to correct it.

So, if the program and it's associated files are placed in D:\Stuff\
the code still wants to read the files from C:\QB\Games\

Is there any way to get the value of where the program is actually EXECUTED from and store this in a string ? Otherwise I cannot share my compiled programs with friends or on my site. The only way would be to insist they follow my exact path stucture when they save the program (very unprofessional!)

I hope you'll understand this explanation.

BTW I'm no code expert either - so library topics are a no-no (sorry I'm not at that level yet)

Many thanks in advance
You can always can specify relative paths. For example (having a variable CurrentPath$ or sumthin), the path where the application is...

Code:
CurrentPath$=""

A directory below...

Code:
CurrentPath$="../"

And such things like

Code:
CurrentPath$="data/libs/directqb/bigdummy/"

Will point to that directory structure below the actual directory. Files can be accessed that way very easily, just

Code:
CompleteFileName$ = CurrentPaht$ + FileName$

Maybe you are specifying fixed paths. Remember that you can always reference any path from where you are, you don't need to start with the rot (i.e. /dos, c:/basic or g:/stupid/folder). If you want to process files in the same directory where the application is, path is empty. If you want to process files in some folders below where the application is, just name the path (as if you were doing CD [foldername] from the current directory).
http://www.geocities.com/gstumpff/utils.zip

there is the file NAME.FUN. It contains a QB routine to return the fully qualified name of the currently running program, from which you can extract the path to that program. (At least, I *think* I remember putting that file in there.)
Many thanks Na_th_an. That was just what I wanted to hear.
It's pretty obvious, but until someone actually tells you you're none the wiser.

BTW - I was using fixed paths as I thought this was the only way to 'point' to the correct location.

Great help - much appreciated.
(BTW Glenn - the link didn't work, but I think Nathan's explanation was sufficient. Cheers anyway)
on it. (It's a geocities site.) You have to copy and paste the URL.
This also works:

Code:
Start:
  CLS
  GOSUB GetDirectory
  PRINT Directory$
  END

GetDirectory:
  file$ = "C:\{{{.}}}"
  t$ = "DIR/A:D/-P|FIND " + CHR$(34) + "Directory" + CHR$(34) + ">" + file$
  SHELL t$
  OPEN file$ FOR INPUT AS #1: LINE INPUT #1, text$: CLOSE #1
  KILL file$
  Directory$ = RIGHT$(text$, LEN(text$) - 14)
  RETURN

Important: Don't forget the <space> after the word FIND in the "t$ = ... " line. I tested this in DOS 6.22 and Win98SE.
This will give you a string called Directory$ that you can manipulate however you need.

Dex

Also, if you want to get a liitle fancier, you could add:

Code:
GetDirectory:
  file = FREEFILE
  temp$ = ENVIRON$("TEMP")
  IF temp$ = "" THEN file$ = "C:\{{{.}}}" ELSE file$ = temp$ + "\{{{.}}}"
  t$ = "DIR/A:D/-P|FIND " + CHR$(34) + "Directory" + CHR$(34) + ">" + file$
  SHELL t$
  OPEN file$ FOR INPUT AS #file: LINE INPUT #file, text$: CLOSE #file
  KILL file$
  Directory$ = RIGHT$(text$, LEN(text$) - 14)
  RETURN
I just realized today that in the above, that the code could be made much simpler. I overlooked a DOS command that I don't use in this format very often.

The line:

t$ = "DIR/ABig Grin/-P|FIND " + CHR$(34) + "Directory" + CHR$(34) + ">" + file$

should be changed to simply: t$ = "CD>" + file$
and the line:

Directory$ = RIGHT$(text$, LEN(text$) - 14)

should simply be: Directory$ = text$

So, the final sub-routine would be:

Code:
GetDirectory:
  file$ = "C:\{{{.}}}"
  t$ = "CD>" + file$
  SHELL t$
  OPEN file$ FOR INPUT AS #1: LINE INPUT #1, text$: CLOSE #1
  KILL file$
  Directory$ = text$
  RETURN

Both methods will work, but this way is much simpler.

Dex
Quote:http://www.geocities.com/gstumpff/utils.zip

there is the file NAME.FUN. It contains a QB routine to return the fully qualified name of the currently running program, from which you can extract the path to that program. (At least, I *think* I remember putting that file in there.)

Good stuff in there. (yep, NAME.FUN is in it) May I stick utils.zip in the code post archives?

- Dav
Quote:
Glenn Wrote:http://www.geocities.com/gstumpff/utils.zip

there is the file NAME.FUN. It contains a QB routine to return the fully qualified name of the currently running program, from which you can extract the path to that program. (At least, I *think* I remember putting that file in there.)

Good stuff in there. (yep, NAME.FUN is in it) May I stick utils.zip in the code post archives?

- Dav