full path to source file __FILE__
Jonathan Marler via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 22 00:53:17 PDT 2016
On Friday, 22 July 2016 at 06:45:58 UTC, Jacob Carlborg wrote:
> On 2016-07-22 04:24, Jonathan Marler wrote:
>
>> The script depends on other files relative to where it exists
>> on the
>> file system. I couldn't think of a better design to find
>> these files
>> then knowing where the script exists, can you?
>
> What kind of files are we talking about. Resource files, config
> files? Are they static? For static resource files you can
> bundle them in the executable with a string import. For config
> files it might be better to store it in a completely different
> directory, like the user's home directory. This actually
> depends on what kind of config files and the operating system.
I suppose I should have been more specific. The script actually
operates on the filesystem relative to where it lives. It copies
files, modifies directories, etc. It is meant to be ran from any
directory, but is only meant to modify the filesystem relative to
where it lives. Take a simple example of a clean script:
/somedir/clean.d
/somedir/build
Say clean.d is meant to remove the build directory that lives in
the same path as the clean.d script itself.
shell/anypath> rdmd /somedir/clean.d
Removing /somedir/build...
It's important to remember that the clean.d script is ran with
rdmd, and that it is meant to be called from any directory.
Since it's ran with rdmd, the thisExePath won't give you the
right directory, and since you can call it from any directory,
you also can't use the current directory. As you can see, what
you really want to know is where the script itself lives.
More information about the Digitalmars-d-learn
mailing list