Qbasicnews.com
July 25, 2021, 01:06:16 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Displaying name of current dir paths using QB  (Read 3233 times)
buckytomsk
New Member

Posts: 13


WWW
« on: March 03, 2003, 07:26:12 PM »

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
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: March 03, 2003, 07:46:04 PM »

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).
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #2 on: March 03, 2003, 10:15:10 PM »

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.)
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
buckytomsk
New Member

Posts: 13


WWW
« Reply #3 on: March 05, 2003, 04:00:23 PM »

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)
Logged
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #4 on: March 05, 2003, 09:06:11 PM »

on it.  (It's a geocities site.)  You have to copy and paste the URL.
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Dex4now
Member
*
Posts: 75


WWW
« Reply #5 on: March 06, 2003, 06:17:18 PM »

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

Logged
Dex4now
Member
*
Posts: 75


WWW
« Reply #6 on: March 13, 2003, 06:34:53 PM »

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/A:D/-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
Logged
Dav
Administrator
Ancient Guru
*****
Posts: 709



WWW
« Reply #7 on: March 14, 2003, 10:34:45 AM »

Quote from: "Glenn"
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
Logged

Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #8 on: March 15, 2003, 12:33:25 AM »

Quote from: "Dav"
Quote from: "Glenn"
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
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!