New __FILE_DIR__ trait?

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 21 19:08:44 PDT 2016


I've got some batch scripts I wanted to convert to D.  I'd like 
users to run them using rdmd, so it's obvious where the source 
code lives and easy to modify.  The problem is that the batch 
scripts I want to convert rely on the %~dp0 variable, which 
contains the path to the batch script itself.  Note that this 
variable is different then the current directory.  I haven't been 
able to find a nice way to do this in D.  (Note that thisExePath 
won't work because rdmd compiles the code to a temporary 
directory, which makes sense.)

Having known about the special __FILE__ and __LINE__ traits, I 
figured there might be a trait for the file directory as well, 
but it appears there is none.  I'd like to see what people think 
about adding a new trait for this.  Maybe something like 
__FILE_DIR__?  This would contain the directory of the 
source-code file it appears in.  Also if this trait was added, 
one could argue that a trait containing the path and the filename 
should also be added, maybe something like __FILE_FULL_PATH__?


P.S. If you know of an existing solution to this problem please 
let me know.


More information about the Digitalmars-d mailing list