CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2004
    Location
    Ireland
    Posts
    34

    Get .Exe folder path

    Hello,

    Is it possible to get the executables folder path at runtime? E.g. "C:\Documents and Settings\MyProgram.exe"

    I need it so as to open a file that’s located in the same folder as the executable and I don’t want to be hard coding it in because if the program is run on a different computer then the path will be wrong.

    Thanks in advance

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    I assume you are using Windows...thus, take a look at the following FAQ...

  3. #3
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    Its in argv[0].

  4. #4
    Join Date
    Jun 2003
    Location
    Cochin
    Posts
    364

    Re: Get .Exe folder path

    Originally posted by Fergal21
    Hello,

    Is it possible to get the executables folder path at runtime? E.g. "C:\Documents and Settings\MyProgram.exe"

    I need it so as to open a file that’s located in the same folder as the executable and I don’t want to be hard coding it in because if the program is run on a different computer then the path will be wrong.

    Thanks in advance
    If you are in windows, use GetModuleFileName(NULL, .....

  5. #5
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    Originally posted by mwilliamson
    Its in argv[0].
    No, it's not. That's a common misconception. argv[0] contains the application name as it was used to invoke your app, which might or might not be the full path name.
    All the buzzt
    CornedBee

  6. #6
    Join Date
    Jun 2003
    Location
    Cochin
    Posts
    364
    Originally posted by CornedBee
    No, it's not. That's a common misconception. argv[0] contains the application name as it was used to invoke your app, which might or might not be the full path name.
    I agree with CornedBee. We can Invoke the application with out specifying the full path in the command prompt.

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