getting __DIR__ and __TIME__ of compilation?
Marco Leise
Marco.Leise at gmx.de
Fri Dec 27 07:23:23 PST 2013
Am Fri, 27 Dec 2013 12:43:15 +0000
schrieb "Ravn" <ravndust at gmail.com>:
> On Friday, 27 December 2013 at 11:56:08 UTC, Ali Çehreli wrote:
> > However, __FILE__ happens to be the current source file that is
> > being compiled but I think the OP wants the current compilation
> > directory. Being a C library file, getcwd() does not work at
> > compile time:
> >
> > import std.stdio;
> >
> > void main()
> > {
> > import std.path: dirName;
> >
> > enum compiledFile = __FILE__;
> > writeln(compiledFile);
> >
> > static const compileTime = __DATE__ ~ " " ~ __TIME__;
> > writeln(compileTime);
> >
> > /*
> > import std.file: getcwd;
> > static const compilationDir = getcwd();
> > writeln(compilationDir);
> >
> > Error: getcwd cannot be interpreted at compile time,
> > because it has no available source code
> > */
> > }
> >
> > Ali
>
> Yes, just like what Ali said above,
>
> __FILE__, __DATE__ and __TIME__ do work for their respective
> usages,
> but I'm also looking for a way to get the current compilation
> directory during compile time, and getcwd() doesn't seem to be
> working.
>
> Isn't there something like __DIR__ or __PATH__ that I can use to
> get that information?
>
> -Ravn-
No, but if you just want the path where your sources are you
could use __FILE__ for any module and cut off the part of
it that belongs to the module path. A lot of Phobos works at
compile time, so you might be able to write a one-liner for
that.
--
Marco
More information about the Digitalmars-d-learn
mailing list