Finding the path to a executable?

evilrat evilrat666 at gmail.com
Tue Aug 6 23:18:32 PDT 2013


On Wednesday, 7 August 2013 at 06:10:16 UTC, Ali Çehreli wrote:
>
> 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

the problem with this that its not absolute path, it is whatever 
string you started your app, i.e. lets assume ~/location/program 
is executable, and we call it
--
cd ~/location
cd ../
./location/prog
---
args[0] would contaion ./location/prog
but combine it with cwd and this would be (always?) the exact 
program path


More information about the Digitalmars-d mailing list