tango.sys.HomeFolder

License:

BSD style: see license.txt

Version:

Initial release: December 2006 Updated and readded: August 2009

Author:

Lars Ivar Igesund, Thomas Kühne, Grzegorz Adam Hankiewicz, sleek

Since:

0.99.9
char[] homeFolder() [@property]
Returns the home folder set in the current environment.
inout(char)[] expandTilde(inout(char)[] inputPath)
Performs tilde expansion in paths.
There are two ways of using tilde expansion in a path. One involves using the tilde alone or followed by a path separator. In this case, the tilde will be expanded with the value of the environment variable HOME. The second way is putting a username after the tilde (i.e. ~john/Mail). Here, the username will be searched for in the user database (i.e. /etc/passwd on Unix systems) and will expand to whatever path is stored there. The username is considered the string after the tilde ending at the first instance of a path separator.

Note that using the ~user syntax may give different values from just ~ if the environment variable doesn't match the value stored in the user database.

When the environment variable version is used, the path won't be modified if the environment variable doesn't exist or it is empty. When the database version is used, the path won't be modified if the user doesn't exist in the database or there is not enough memory to perform the query.

Returns:

inputPath with the tilde expanded, or just inputPath if it could not be expanded.

Throws:

OutOfMemoryException if there is not enough memory to perform the database lookup for the ~user syntax.

Examples:

1
2
3
4
5
6
7
import tango.sys.HomeFolder;

void processFile(char[] filename)
{
     char[] path = expandTilde(filename);
    ...
}

1
2
3
4
5
6
7
8
9
import tango.sys.HomeFolder;

const char[] RESOURCE_DIR_TEMPLATE = "~/.applicationrc";
char[] RESOURCE_DIR;    // This gets expanded below.

static this()
{
    RESOURCE_DIR = expandTilde(RESOURCE_DIR_TEMPLATE);
}