On Friday, 22 July 2016 at 02:08:44 UTC, Jonathan Marler wrote:
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.

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.

Reply via email to