July 23, 2016
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
>
>
What about using a wrapper around rdmd, so the program is executed with an
additional parameter or an environment variable containing "FULL_PATH".

When I started with D, I "accidentaly" wrote my own replacement script for rdmd
compiling xyz.d with dmd to xyz or calling xyz depending on the modification times of the files.

Regards mt.


July 27, 2016
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 ", ???);
> }

For others who may see this thread, the __FULL_FILE_PATH__ special trait was added to the dmd compiler with this PR: https://github.com/dlang/dmd/pull/5959

At the time of this post, the latest released version of D is 2.071.1, so this trait should be available on any release after that.
May 29, 2018
On Wednesday, 27 July 2016 at 13:58:22 UTC, Jonathan Marler 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 ", ???);
>> }
>
> For others who may see this thread, the __FULL_FILE_PATH__ special trait was added to the dmd compiler with this PR: https://github.com/dlang/dmd/pull/5959
>
> At the time of this post, the latest released version of D is 2.071.1, so this trait should be available on any release after that.

Except it doesn't?

auto x(string fp = __FULL_FILE_PATH__)()
{
   pragma(msg, fp);
}

?
May 29, 2018
On 05/29/2018 02:34 PM, DigitalDesigns wrote:
 > auto x(string fp = __FULL_FILE_PATH__)()
> {
>     pragma(msg, fp);
> }
> 
> ?

__FILE_FULL_PATH__

  https://dlang.org/spec/expression#specialkeywords

Ali
May 29, 2018
On 5/29/18 5:34 PM, DigitalDesigns wrote:
> On Wednesday, 27 July 2016 at 13:58:22 UTC, Jonathan Marler 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 ", ???);
>>> }
>>
>> For others who may see this thread, the __FULL_FILE_PATH__ special trait was added to the dmd compiler with this PR: https://github.com/dlang/dmd/pull/5959
>>
>> At the time of this post, the latest released version of D is 2.071.1, so this trait should be available on any release after that.
> 
> Except it doesn't?
> 
> auto x(string fp = __FULL_FILE_PATH__)()
> {
>     pragma(msg, fp);
> }
> 
> ?

__FILE_FULL_PATH__, not __FULL_FILE_PATH__ (yes, it was wrong in the post you quoted).

In addition, you must instantiate the template:

void main()
{
    x();
}

-Steve
May 29, 2018
On Tuesday, 29 May 2018 at 21:41:37 UTC, Ali Çehreli wrote:
> On 05/29/2018 02:34 PM, DigitalDesigns wrote:
>  > auto x(string fp = __FULL_FILE_PATH__)()
>> {
>>     pragma(msg, fp);
>> }
>> 
>> ?
>
> __FILE_FULL_PATH__
>
>   https://dlang.org/spec/expression#specialkeywords
>
> Ali

Lol, thanks:


1 2 3 4
Next ›   Last »