DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   can i get the full file path from specified file name (.exe) (http://www.daniweb.com/forums/thread132759.html)

lahom Jul 5th, 2008 12:26 am
can i get the full file path from specified file name (.exe)
 
pleeeeeease
can i get the full file path from specified file name (.exe)
an arbitrary file (.exe)

Ancient Dragon Jul 5th, 2008 8:46 am
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.

Duoas Jul 5th, 2008 6:33 pm
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.

Ancient Dragon Jul 5th, 2008 6:45 pm
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.

Duoas Jul 5th, 2008 7:54 pm
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.


All times are GMT -4. The time now is 7:28 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC