full path to source file __FILE__
Jonathan Marler via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 21 15:50:26 PDT 2016
On Thursday, 21 July 2016 at 22:39:45 UTC, Steven Schveighoffer
wrote:
> On 7/21/16 3:54 PM, 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 ", ???);
>> }
>
> Sure seems like an unwanted limitation.
>
> rdmd does forward all dmd options, but there isn't really an
> option to say "put the exe in the source path".
>
> You should file an enhancement.
>
> -Steve
An option for rdmd would be good, but then requires the user to
call rdmd in a particular way. It doesnt allow the script itself
know where it lives, which is needed in my case.
More information about the Digitalmars-d-learn
mailing list