Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1675
Number of posts: 4764

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Opening Binary Files Posted by Tommy Tyler on 18 Aug 2005 at 6:28 AM
Using QuickBasic 7.1 on WinXP. My program will OPEN <filename.dat> just fine if the file is in the same directory as QBX.exe, but not if it is in another directory. For example:

OPEN "<filename.dat>" FOR BINARY AS #1

works just fine. But:

OPEN "C:\<directory>\<sub-directory>\<filename.dat>" FOR BINARY AS #1

(or other variations, such as omitting drive letter, putting only <filename.dat> in quotes, etc.) gives path errors.

Is there a way to do this?
Report
Re: Opening Binary Files Posted by anthrax11 on 19 Aug 2005 at 10:36 AM
: Using QuickBasic 7.1 on WinXP. My program will OPEN <filename.dat> just fine if the file is in the same directory as QBX.exe, but not if it is in another directory. For example:
:
: OPEN "<filename.dat>" FOR BINARY AS #1
:
: works just fine. But:
:
: OPEN "C:\<directory>\<sub-directory>\<filename.dat>" FOR BINARY AS #1
:
: (or other variations, such as omitting drive letter, putting only <filename.dat> in quotes, etc.) gives path errors.
:
: Is there a way to do this?
:

Probably, the problem is, that your filename or directories have names longer than 13 characters. Ovbiously, DOS doesnt support long filenames, so the solution is to make short filenames:

For example:
OPEN "C:\Myfoldernumber1\importantstuff\Iwantfilehere\Filename.dat" FOR BINARY AS #1
Should be:
OPEN "C:\Myfold~1\import~1\Iwantm~1\Filename.dat" FOR BINARY AS #1

If you have spaces in your filenames or if the above doesnt work, then Im clueless.
Report
Re: Opening Binary Files Posted by DrMarten on 19 Aug 2005 at 6:43 PM
This message was edited by DrMarten at 2005-8-19 18:44:41

: : Using QuickBasic 7.1 on WinXP. My program will OPEN <filename.dat> just fine if the file is in the same directory as QBX.exe, but not if it is in another directory. For example:
: :
: : OPEN "<filename.dat>" FOR BINARY AS #1
: :
: : works just fine. But:
: :
: : OPEN "C:\<directory>\<sub-directory>\<filename.dat>" FOR BINARY AS #1
: :
: : (or other variations, such as omitting drive letter, putting only <filename.dat> in quotes, etc.) gives path errors.
: :
: : Is there a way to do this?
: :
:
: Probably, the problem is, that your filename or directories have names longer than 13 characters. Ovbiously, DOS doesnt support long filenames, so the solution is to make short filenames:
:
: For example:
: OPEN "C:\Myfoldernumber1\importantstuff\Iwantfilehere\Filename.dat" FOR BINARY AS #1
: Should be:
: OPEN "C:\Myfold~1\import~1\Iwantm~1\Filename.dat" FOR BINARY AS #1
:
: If you have spaces in your filenames or if the above doesnt work, then Im clueless.
:



=================

I have not looked at QBasic for ages but is there a SETPATH or a PATH= command?

You might be able to use a string in the OPEN command like

OPEN A$

and set A$ to one of the strings you typed.

To find out how your PC stores a filename in the 8.3 mode of DOS go to>
START then RUN
type in CMD to open a DOS window
Look at the appropriate directories using CD and DIR as usual

If a filename you know is longer (within Windows) it will appear with the "~" character in it which is SHIFT with the # key (next to BACKSPACE) on a UK keyboard.

Hope this helps?

Regards,

DrM



Report
Re: Opening Binary Files Posted by Tommy Tyler on 20 Aug 2005 at 7:35 AM
: : Probably, the problem is, that your filename or directories have names longer than 13 characters. : :

That was it. Also, some of the sub-directories in my path had spaces and you have to close those up. For example, <THIS PLACE> has to changed to <THISPL~1>. Many thanks for your help.
Report
Re: Opening Binary Files Posted by DrMarten on 20 Aug 2005 at 2:31 PM
This message was edited by DrMarten at 2005-8-20 14:31:57

: : : Probably, the problem is, that your filename or directories have names longer than 13 characters. : :
:
: That was it. Also, some of the sub-directories in my path had spaces and you have to close those up. For example, <THIS PLACE> has to changed to <THISPL~1>. Many thanks for your help.
:
==================================================

Any paths that have a space in them also need to be in quotes.

Eg C:\My file.text is really reffered to as "C:\My file.text"
as DOS tries to decipher what you type by looking at the spaces ( except when the spaces are between the quote marks> " " <


Regards,

DrM



Report
Re: Opening Binary Files Posted by anthrax11 on 20 Aug 2005 at 3:15 PM
: This message was edited by DrMarten at 2005-8-20 14:31:57

: : : : Probably, the problem is, that your filename or directories have names longer than 13 characters. : :
: :
: : That was it. Also, some of the sub-directories in my path had spaces and you have to close those up. For example, <THIS PLACE> has to changed to <THISPL~1>. Many thanks for your help.
: :
: ==================================================
:
: Any paths that have a space in them also need to be in quotes.
:
: Eg C:\My file.text is really reffered to as "C:\My file.text"
: as DOS tries to decipher what you type by looking at the spaces ( except when the spaces are between the quote marks> " " <
:
:
: Regards,
:
: DrM
:
:
:
:
Im not sure i fully understand you.
Are you tying to say:
"
This doesnt work:
OPEN C:\My file.text FOR BINAY AS #1
but this does:
OPEN "C:\My file.text" FOR BINAY AS #1
"?
If so then Ill have you know that you have to put the paths into quotes either way in QB.
Btw, DOS doesnt support 4 letter extensions, QBASIC just assumes "file.tex" instead of "file.text"

About spaces, the spaces can exist with short filenames like this:
"My file.txt"
But the long filenames need to be closed up like Tommy Tyler said:
"Myfile~1.txt"





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.