On Friday, 22 July 2016 at 05:41:00 UTC, fdgdsgf wrote:
On Thursday, 21 July 2016 at 19:54:34 UTC, Jonathan Marler
wrote:
Is there a way to get the full path of the current source
file? Something like:
__FILE_FULL_PATH__
I'm asking because I'm rewriting a batch script in D, meant to
be ran with rdmd. However, the script needs to know it's own
path. The original batch script uses the %~dp0 variable for
this, but I'm at a loss on how to do this in D. Since rdmd
compiles the executable to the %TEMP% directory, thisExePath
won't work.
BATCH
-----
echo "Directory of this script is " %~dp0
DLANG
-----
import std.stdio;
int main(string[] args) {
writeln("Directory of this script is ", ???);
}
What's wrong with __FILE__.dirName ?
It's kinda weird, sometimes I've noticed that the __FILE__
keyword is an absolute path, and sometimes it isn't. If it was
always an absolute path, that would work. I decided to take a
stab at implementing this in the dmd compiler:
https://github.com/dlang/dmd/pull/5959
It adds a __FILE_FULL_PATH__ trait which would solve the issue.