Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.


Encapsulate path and file names.
struct FileName;
Encapsulate path and file names.
pure nothrow this(const(char)[] str);
static pure nothrow FileName create(const(char)* name);
static pure nothrow @nogc bool equals(const(char)* name1, const(char)* name2);

static pure nothrow @nogc bool equals(const(char)[] name1, const(char)[] name2);
Compare two name according to the platform's rules (case sensitive or not)
static pure nothrow @nogc bool absolute(const(char)* name);

static pure nothrow @nogc @safe bool absolute(const(char)[] name);
Determine if path is absolute.
const(char)* name path
true if absolute path name.
static nothrow const(char)* toAbsolute(const(char)* name, const(char)* base = null);
Return the given name as an absolute path
const(char)* name path
const(char)* base the absolute base to prefix name with if it is relative
name as an absolute path relative to base
static pure nothrow @nogc const(char)* ext(const(char)* str);

static pure nothrow @nogc @safe const(char)[] ext(const(char)[] str);
Determine file name extension as slice of input.
const(char)* str file name
filename extension (read-only). Points past '.' of extension. If there isn't one, return null.
static nothrow const(char)* removeExt(const(char)* str);

static nothrow const(char)[] removeExt(const(char)[] str);
Return file name without extension.

TODO Once slice are used everywhere and \0 is not assumed, this can be turned into a simple slicing.

const(char)* str file name
mem.xmalloc'd filename with extension removed.
static pure nothrow @nogc const(char)* name(const(char)* str);

static pure nothrow @nogc @safe const(char)[] name(const(char)[] str);
Return filename name excluding path (read-only).
static nothrow const(char)* path(const(char)* str);

static nothrow const(char)[] path(const(char)[] str);
Return path portion of str. returned string is newly allocated Path does not include trailing path separator.
static nothrow const(char)[] replaceName(const(char)[] path, const(char)[] name);
Replace filename portion of path.
static nothrow const(char)* combine(const(char)* path, const(char)* name);

static nothrow const(char)[] combine(const(char)[] path, const(char)[] name);
Combine a path and a file name
const(char)* path Path to append to
const(char)* name Name to append to path
The \0 terminated string which is the combination of path and name and a valid path.
static nothrow void splitPath(int delegate(const(char)*) nothrow sink, const(char)* path);
Split path (such as that returned by getenv("PATH")) into pieces, each piece is mem.xmalloc'd Handle double quotes and ~. Pass the pieces to sink()
int delegate(const(char)*) nothrow sink send the path pieces here, end when sink() returns !=0
const(char)* path the path to split up.
static pure nothrow char[] addExt(const(char)[] name, const(char)[] ext);
Add the extension ext to name, regardless of the content of name
const(char)[] name Path to append the extension to
const(char)[] ext Extension to add (should not include '.')
A newly allocated string (free with
static nothrow const(char)* defaultExt(const(char)* name, const(char)* ext);

static nothrow const(char)[] defaultExt(const(char)[] name, const(char)[] ext);
Free returned value with FileName::free()
static nothrow const(char)* forceExt(const(char)* name, const(char)* ext);

static nothrow const(char)[] forceExt(const(char)[] name, const(char)[] ext);
Free returned value with FileName::free()
static pure nothrow @nogc bool equalsExt(const(char)* name, const(char)* ext);

static pure nothrow @nogc bool equalsExt(const(char)[] name, const(char)[] ext);
true if name's extension is ext
const pure nothrow @nogc bool equalsExt(const(char)* ext);
Return !=0 if extensions match.
static nothrow const(char)* searchPath(Strings* path, const(char)* name, bool cwd);
Search paths for file.
Strings* path array of path strings
const(char)* name file to look for
bool cwd true means search current directory before searching path
if found, filename combined with path, otherwise null
static pure nothrow @nogc @safe size_t findReservedChar(const(char)[] name);
Determine if path contains reserved character.
const(char)[] name path
index of the first reserved character in path if found, size_t.max otherwise
static pure nothrow @nogc @safe bool refersToParentDir(const(char)[] name);
Determine if path has a reference to parent directory.
const(char)[] name path
true if path contains '..' reference to parent directory
static nothrow int exists(const(char)* name);

static nothrow int exists(const(char)[] name);
Check if the file the path points to exists
0 if it does not exists 1 if it exists and is not a directory 2 if it exists and is a directory
static nothrow bool ensurePathExists(const(char)[] path);

static nothrow bool ensurePathExists(const(char)* path);
Ensure that the provided path exists
Accepts a path to either a file or a directory. In the former case, the basepath (path to the containing directory) will be checked for existence, and created if it does not exists. In the later case, the directory pointed to will be checked for existence and created if needed.
const(char)[] path a path to a file or a directory
true if the directory exists or was successfully created
static nothrow const(char)* canonicalName(const(char)* name);

static nothrow const(char)[] canonicalName(const(char)[] name);
Return canonical version of name. This code is high risk.
static pure nothrow void free(const(char)* str);
Free memory allocated by FileName routines