Finding the path to a executable?

Alan alanpotteiger at gmail.com
Tue Aug 6 23:15:03 PDT 2013


On Wednesday, 7 August 2013 at 06:10:16 UTC, Ali Çehreli wrote:
> On 08/06/2013 10:31 PM, 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!
>
> First program argument is the absolute path to the executable. 
> (I am not sure whether this is portable.)
>
> import std.stdio;
> import std.path;
>
> void main(string[] args)
> {
>     writefln("I am program '%s' in '%s'.",
>              baseName(args[0]), dirName(args[0]));
> }
>
> Ali

Just missed your response!  And no that doesn't fetch the 
absolute path, just the relative path.  Thanks for help so far 
though!


More information about the Digitalmars-d mailing list