CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2007
    Posts
    20

    Open file wont work, it says wrong path

    I'm testing out how to open files with C++ and I've come across a problem. It seems when I try to open a path that has no spaces in it, it works fine. But when I try to open a path with spaces it has an error message that says could not open file and it spouts the path but it stops short where the space is and doesn't seem to read the link after the space occured. Does anyone know what I'm doing wrong?

    For instance this does not work:
    Code:
    #include <stdafx.h>
    #include <iostream>
    using namespace std;
    #include <fstream>
    
    
    int main()
    {
        system("START C:\\Program Files\\FlashFXP\\FlashFXP.exe");
    }

    This one DOES work:

    Code:
    #include <stdafx.h>
    #include <iostream>
    using namespace std;
    #include <fstream>
    
    
    int main()
    {
        system("START C:\\WINDOWS\\notepad.exe");
    }
    Last edited by wolfcry044; November 13th, 2007 at 10:57 PM.

  2. #2
    Join Date
    Jun 2004
    Location
    India
    Posts
    432

    Re: Open file wont work, it says wrong path

    The file name (with a space in it) needs to be enclosed in qoutes.
    Say no to supplying ready made code for homework/work assignments!!

    Please rate this post!

  3. #3
    Join Date
    Aug 2006
    Posts
    157

    Re: Open file wont work, it says wrong path

    Put quotes around your path like so:
    Code:
    int main()
    {
        system("START \"C:\\Program Files\\FlashFXP\\FlashFXP.exe\"");
    }
    sockman

  4. #4
    Join Date
    Mar 2007
    Posts
    20

    Re: Open file wont work, it says wrong path

    Now I get a window that pops up when I execute it instead of it executing the program. Here's a screenshot of what pops up:


  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Open file wont work, it says wrong path

    Quote Originally Posted by wolfcry044
    Now I get a window that pops up when I execute it instead of it executing the program.
    I don't know what you're trying to show us, but what did you expect to happen? If you went to the command line and typed in that start command, what would happen? If it's the same thing as you're seeing now, then that is what you have.

    I see the name of the program in the title bar of the command window, so I don't see anything that it shouldn't be doing. To me, the program, FlashFXP.exe *is* running as you've told it to run.

    Regards,

    Paul McKenzie

  6. #6
    Join Date
    Mar 2007
    Posts
    20

    Re: Open file wont work, it says wrong path

    But it doesn't open the program up or run it. It just opens that window.

    When I tell it to open the calculator, it opens it up. But not when I tell it to run anything in program files.

    the name is there in the bar because I opened the program myself.

  7. #7
    Join Date
    Mar 2007
    Posts
    20

    Re: Open file wont work, it says wrong path

    The reason the program is running in that screenshot is because I ran it manually, not because that program opened it up. I even tried closing the program and running the .exe again and it still didn't pop any program up. It was just an accident that the flashfxp program was running at the time because I forgot I had manually opened an instance up, the program didn't open it.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Open file wont work, it says wrong path

    Isn't it expecting a fillename to play as well?

    Try appname.exe /?

    to see if they list parameters to supply
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Open file wont work, it says wrong path

    You still didn't answer my question -- did you type in the "start" command from the command-line? If you did, what results did you get? Is it the same as if you wrote a program and called the "start" command?

    Regards,

    Paul McKenzie

  10. #10
    Join Date
    Mar 2007
    Posts
    20

    Re: Open file wont work, it says wrong path

    No, when I type it in the start command I get the program popping up. When I execute the program I made I get nothing but a dos window.

  11. #11
    Join Date
    Mar 2007
    Posts
    20

    Re: Open file wont work, it says wrong path

    In fact, the start run command is where I got the url in the first place.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured