Finding the path to a executable?
Alan
alanpotteiger at gmail.com
Tue Aug 6 23:18:25 PDT 2013
On Wednesday, 7 August 2013 at 06:13:59 UTC, evilrat wrote:
> On Wednesday, 7 August 2013 at 05:31:24 UTC, Alan wrote:
>> Hello! This may seem like a simple question, maybe an
>> embarassing question but how would I fetch the absolute path
>> to the directory where my executable is located? My wording
>> is known to be confusing so I will give an example:
>>
>> cd ~/projects/program
>> dmd Program.d -ofProgram
>>
>> That executable would be located in
>> /home/alan/projects/program for example. SO my question is
>> how would I fetch the absolute path to that directory?
>>
>> Thanks for any help!
>
> you mean absolute path at runtime? this is passed as args[0] in
> main(string[] args). though it contains not path but string
> used to launch ur program( for example "./program" when
> launched from its location, and full program path when
> double-clicked).
>
> also you can use getcwd() from std.path.
>
> but you can't rely on it as both of this takes "caller"
> location.
>
> may be this helps you :
> http://msdn.microsoft.com/en-us/library/ms683197(VS.85).aspx
> http://man7.org/linux/man-pages/man3/getcwd.3.html
>
> p.s. such question better ask in learn section
Sorry about the section mishap, I'm new here!
Believe me I have tried all sorts of combonations of this but
it's not guarunteed accuracy in certain situations, I thought
there would be a solution in phobos library I was missing but
maybe I will have to write something complex out.
Thanks for all the help so far!
More information about the Digitalmars-d
mailing list