Finding the path to a executable?
evilrat
evilrat666 at gmail.com
Tue Aug 6 23:13:58 PDT 2013
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
More information about the Digitalmars-d
mailing list