943,604 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3344
  • C++ RSS
Jul 5th, 2008
0

can i get the full file path from specified file name (.exe)

Expand Post »
pleeeeeease
can i get the full file path from specified file name (.exe)
an arbitrary file (.exe)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
lahom is offline Offline
42 posts
since Apr 2008
Jul 5th, 2008
0

Re: can i get the full file path from specified file name (.exe)

look at argv[0] -- some compilers put the full path in there.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 5th, 2008
0

Re: can i get the full file path from specified file name (.exe)

...but that is not guaranteed. It is usually a safe bet that it contains at least the simple name of the executable ("foo.exe"). It may also contain either an absolute path or a relative path.

On POSIX systems (Unix, Linux, Mac OS X, etc), use getcwd() and combine the result with argv[0].

On Win32, use GetModuleFileName().

Hope this helps.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Jul 5th, 2008
0

Re: can i get the full file path from specified file name (.exe)

>>but that is not guaranteed
Yes I know, which is why I made the qualified statement. Only some compilers do that.

getcwd() only gets the current working directory, which is also available in MS-Windows. If the program changes directories before calling getcwd() itt will not give you what you are looking for, assuming you want the path to the *.exe file.

I don't know if there is a POSIX equivalent to GetModueFileName(), but getcwd() is not it.
Last edited by Ancient Dragon; Jul 5th, 2008 at 6:48 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Jul 5th, 2008
0

Re: can i get the full file path from specified file name (.exe)

> Yes I know...
I know you know... But I thought I'd give the OP more.

There is no POSIX equivalent to GetModuleFileName(). You have to use getcwd() as soon as your program starts or at least before anything changes the current directory.

Hope this helps.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Size of array passed as parameter.
Next Thread in C++ Forum Timeline: Couldn't pass variable values to another form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC