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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 42
Reputation: lahom is an unknown quantity at this point 
Solved Threads: 0
lahom lahom is offline Offline
Light Poster

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

 
0
  #1
Jul 5th, 2008
pleeeeeease
can i get the full file path from specified file name (.exe)
an arbitrary file (.exe)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,389
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

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

 
0
  #2
Jul 5th, 2008
look at argv[0] -- some compilers put the full path in there.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

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

 
0
  #3
Jul 5th, 2008
...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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,389
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

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

 
0
  #4
Jul 5th, 2008
>>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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

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

 
0
  #5
Jul 5th, 2008
> 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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC