dmd.root.filename
Encapsulate path and file names.
License
Source: root/filename.d
Documentation: https://dlang.org/phobos/dmd_root_filename.html
-
Declaration
structFileName;Encapsulate path and file names.
-
Declaration
pure nothrow this(const(char)[]str); -
Declaration
static pure nothrow @nogc boolequals(const(char)*name1, const(char)*name2);
static pure nothrow @nogc boolequals(const(char)[]name1, const(char)[]name2);Compare two name according to the platform's rules (case sensitive or not)
-
Declaration
static pure nothrow @nogc boolabsolute(const(char)*name);
static pure nothrow @nogc boolabsolute(const(char)[]name);Determine if path is
absolute.Parameters
const(char)*namepath
Return Value
trueifabsolutepathname. -
Declaration
static nothrow const(char)*toAbsolute(const(char)*name, const(char)*base= null);Return the given
nameas an absolute pathParameters
const(char)*namepath
const(char)*basethe absolute
baseto prefixnamewith if it is relativeReturn Value
nameas an absolute path relative tobase -
Declaration
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.
Parameters
const(char)*strfile name
Return Value
filename extension (read-only). Points past '.' of extension. If there isn't one, return
null. -
Declaration
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
\0is not assumed, this can be turned into a simple slicing.Parameters
const(char)*strfile name
Return Value
mem.xmalloc'd filename with extension removed.
-
Declaration
static pure nothrow @nogc const(char)*name(const(char)*str);
static pure nothrow @nogc const(char)[]name(const(char)[]str);Return filename
nameexcluding path (read-only). -
Declaration
static nothrow const(char)*path(const(char)*str);
static nothrow const(char)[]path(const(char)[]str);Return
pathportion ofstr. returned string is newly allocated Path does not include trailingpathseparator. -
Declaration
static nothrow const(char)[]replaceName(const(char)[]path, const(char)[]name);Replace filename portion of
path. -
Declaration
static nothrow const(char)*combine(const(char)*path, const(char)*name);
static nothrow const(char)[]combine(const(char)[]path, const(char)[]name);Combine a
and a filepathnameParameters
const(char)*pathPath to append to
const(char)*nameName to append to
pathReturn Value
The
\0terminated string which is the combination ofandpathand a validnamepath. -
Declaration
static nothrow voidsplitPath(int delegate(const(char)*) nothrowsink, const(char)*path);Split
path(such as that returned bygetenv("PATH")) into pieces, each piece is mem.xmalloc'd Handle double quotes and ~. Pass the pieces tosink()Parameters
int delegate(const(char)*) nothrowsinksend the
pathpieces here, end whensink() returns !=0const(char)*paththe
pathto split up. -
Declaration
static pure nothrow char[]addExt(const(char)[]name, const(char)[]ext);Add the extension
toext, regardless of the content ofnamenameParameters
const(char)[]namePath to append the extension to
const(char)[]extExtension to add (should not include '.')
Return Value
A newly allocated string (free with
FileName.free) -
Declaration
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()
-
Declaration
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()
-
Declaration
static pure nothrow @nogc boolequalsExt(const(char)*name, const(char)*ext);
static pure nothrow @nogc boolequalsExt(const(char)[]name, const(char)[]ext);Return Value
trueif's extension isnameext -
Declaration
const pure nothrow @nogc boolequalsExt(const(char)*ext);Return !=0 if extensions match.
-
Declaration
static nothrow const(char)*searchPath(Strings*path, const(char)*name, boolcwd);Search paths for file.
Parameters
Strings*patharray of
pathstringsconst(char)*namefile to look for
boolcwdtruemeans search current directory before searchingpathReturn Value
if found, filename combined with
path, otherwisenull -
Declaration
static pure nothrow @nogc size_tfindReservedChar(const(char)*name);Determine if path contains reserved character.
Parameters
const(char)*namepath
Return Value
index of the first reserved character in path if found, size_t.max otherwise
-
Declaration
static pure nothrow @nogc boolrefersToParentDir(const(char)*name);Determine if path has a reference to parent directory.
Parameters
const(char)*namepath
Return Value
trueif path contains '..' reference to parent directory -
Declaration
static nothrow intexists(const(char)*name);
static nothrow intexists(const(char)[]name);Check if the file the
pathpoints toexistsReturn Value
0 if it does not
exists1 if itexistsand is not a directory 2 if itexistsand is a directory -
Declaration
static nothrow boolensurePathExists(const(char)[]path);
static nothrow boolensurePathExists(const(char)*path);Ensure that the provided
pathexistsDiscussion
Accepts a
pathto either a file or a directory. In the former case, the basepath (pathto 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.Parameters
const(char)[]patha
pathto a file or a directoryReturn Value
trueif the directory exists or was successfully created -
Declaration
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. -
Declaration
static pure nothrow voidfree(const(char)*str);Free memory allocated by FileName routines
-