Getting environment variables?
Stewart Gordon
smjg_1998 at yahoo.com
Sat Nov 22 10:52:37 PST 2008
"Christopher Wright" <dhasenan at gmail.com> wrote in message
news:gg9h3f$9uo$1 at digitalmars.com...
> Hey all,
>
> How do I get environment variables in a D program?
std.c.stdlib.getenv
http://www.cplusplus.com/reference/clibrary/cstdlib/getenv.html
> I specifically want the path to a user's home folder.
Platform-dependent.
For Windows, you can use the concatenation of HOMEDRIVE and HOMEPATH, but I
don't know under which versions of Windows these variables are actually set.
----------
import std.c.stdlib, std.string, std.stdio;
void main() {
string homeDrive, homePath;
homeDrive = toString(getenv("HOMEDRIVE")).dup;
homePath = toString(getenv("HOMEPATH")).dup;
writefln("%s%s", homeDrive, homePath);
}
----------
For Unix, I'm informed that the HOME environment variable does it.
http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2005-09/0092.html
HTH
Stewart.
--
My e-mail address is valid but not my primary mailbox. Please keep replies
on the 'group where everybody may benefit.
More information about the Digitalmars-d-learn
mailing list