Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening files from the current directory?

Status
Not open for further replies.

Aron1

Programmer
Mar 19, 2003
11
HU
I have used in my program the OPEN statement like this:
Code:
 OPEN "c:\qbasic\game\something.dat" FOR INPUT #1
What if I copy the program to another computer? If there is no "C:\qbasic\game" directory it won't find the file.
It isn't working when I try this way:
Code:
OPEN "something.dat" FOR INPUT AS #1

Is there any way in QB to open file from the CURRENT directory?
 
yeah...

just leave off the path...

OPEN "something.dat" FOR INPUT #1


Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
oops... I answered without reading the rest of the post...

Open "file.ext" For Input As #1
...will open "file.ext" from the current directory

If this is not working... you are in a different directory than what you THINK you are in...

If you are using a shortcut to open Qbasic... Make sure the Working Directoy is set properly...

you can use CHDIR to change your current directory...

for debuging purposes, you can throw in a SHELL command, by it self to see what directory you are actually in...


Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
That does not always work. If a previous file command was used that tells the program to look in another directory, the next file command will look in the same place as the previous one. I get by the problem, by checking to see if C: is a valid drive. If it is, I just store my stuff there.
 
So, are you saying if the current directory is C:\QB
and you say: OPEN "C:\AUTOEXEC.BAT" FOR INPUT AS #1

then say: OPEN "QB.BI" FOR INPUT AS #1

it looks for "c:\qb.bi" instead of "c:\qb\qb.bi" ?

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
That is what I am saying. But maybe I am wrong. I'll check here. Forgive my post, I was wrong. Check the link that you use to run qbasic. See what the current working directory is.
 
Thank you!

I was NOT in the directory I thought I was.
It is now working.
 
Is it possible to use a
CHDIR "."
or will that not work?

-----------------------
Soon to come - a QBasic contest forum!
-----------------------
 
you can try...

it won't hurt anything...

CHDIR "should" work the same as CD in dos...

I know you can say "C:\" but I never tried "." before...

though, I do always write to the C: drive on my pc...

you might also try CHDIR ".\"

Good Luck,

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top