Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Opening Binary Files

Tommy TylerTommy Tyler Posts: 2Member
Using QuickBasic 7.1 on WinXP. My program will OPEN just fine if the file is in the same directory as QBX.exe, but not if it is in another directory. For example:

OPEN "" FOR BINARY AS #1

works just fine. But:

OPEN "C:" FOR BINARY AS #1

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

Is there a way to do this?

Comments

  • anthrax11anthrax11 Posts: 511Member
    : Using QuickBasic 7.1 on WinXP. My program will OPEN just fine if the file is in the same directory as QBX.exe, but not if it is in another directory. For example:
    :
    : OPEN "" FOR BINARY AS #1
    :
    : works just fine. But:
    :
    : OPEN "C:" FOR BINARY AS #1
    :
    : (or other variations, such as omitting drive letter, putting only 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:Myfoldernumber1importantstuffIwantfilehereFilename.dat" FOR BINARY AS #1
    Should be:
    OPEN "C:Myfold~1import~1Iwantm~1Filename.dat" FOR BINARY AS #1

    If you have spaces in your filenames or if the above doesnt work, then Im clueless.
  • DrMartenDrMarten Posts: 748Member
    [b][red]This message was edited by DrMarten at 2005-8-19 18:44:41[/red][/b][hr]
    : : Using QuickBasic 7.1 on WinXP. My program will OPEN just fine if the file is in the same directory as QBX.exe, but not if it is in another directory. For example:
    : :
    : : OPEN "" FOR BINARY AS #1
    : :
    : : works just fine. But:
    : :
    : : OPEN "C:" FOR BINARY AS #1
    : :
    : : (or other variations, such as omitting drive letter, putting only 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:Myfoldernumber1importantstuffIwantfilehereFilename.dat" FOR BINARY AS #1
    : Should be:
    : OPEN "C:Myfold~1import~1Iwantm~1Filename.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



  • Tommy TylerTommy Tyler Posts: 2Member
    : : 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, has to changed to . Many thanks for your help.
  • DrMartenDrMarten Posts: 748Member
    [b][red]This message was edited by DrMarten at 2005-8-20 14:31:57[/red][/b][hr]
    : : : 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, has to changed to . 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



  • anthrax11anthrax11 Posts: 511Member
    : [b][purple]This message was edited by DrMarten at 2005-8-20 14:31:57[/purple][/b][hr]
    : : : : 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, has to changed to . 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"


Sign In or Register to comment.