dmd.root.filename
Encapsulate path and file names.
License
Source: root/filename.d
Documentation: https://dlang.org/phobos/dmd_root_filename.html
-
Declaration
struct
FileName
;Encapsulate path and file names.
-
Declaration
pure nothrow this(const(char)[]
str
); -
Declaration
static pure nothrow @nogc bool
equals
(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 bool
absolute
(const(char)*name
);
static pure nothrow @nogc boolabsolute
(const(char)[]name
);Determine if path is
absolute
.Parameters
const(char)*
name
path
Return Value
true
ifabsolute
pathname
. -
Declaration
static nothrow const(char)*
toAbsolute
(const(char)*name
, const(char)*base
= null);Return the given
name
as an absolute pathParameters
const(char)*
name
path
const(char)*
base
the absolute
base
to prefixname
with if it is relativeReturn Value
name
as 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)*
str
file 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
\0
is not assumed, this can be turned into a simple slicing.Parameters
const(char)*
str
file 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
name
excluding path (read-only). -
Declaration
static nothrow const(char)*
path
(const(char)*str
);
static nothrow const(char)[]path
(const(char)[]str
);Return
path
portion ofstr
. returned string is newly allocated Path does not include trailingpath
separator. -
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 filepath
name
Parameters
const(char)*
path
Path to append to
const(char)*
name
Name to append to
path
Return Value
The
\0
terminated string which is the combination of
andpath
and a validname
path
. -
Declaration
static nothrow void
splitPath
(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)*) nothrow
sink
send the
path
pieces here, end whensink
() returns !=0const(char)*
path
the
path
to split up. -
Declaration
static pure nothrow char[]
addExt
(const(char)[]name
, const(char)[]ext
);Add the extension
toext
, regardless of the content ofname
name
Parameters
const(char)[]
name
Path to append the extension to
const(char)[]
ext
Extension 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 bool
equalsExt
(const(char)*name
, const(char)*ext
);
static pure nothrow @nogc boolequalsExt
(const(char)[]name
, const(char)[]ext
);Return Value
true
if
's extension isname
ext
-
Declaration
const pure nothrow @nogc bool
equalsExt
(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*
path
array of
path
stringsconst(char)*
name
file to look for
bool
cwd
true
means search current directory before searchingpath
Return Value
if found, filename combined with
path
, otherwisenull
-
Declaration
static pure nothrow @nogc size_t
findReservedChar
(const(char)*name
);Determine if path contains reserved character.
Parameters
const(char)*
name
path
Return Value
index of the first reserved character in path if found, size_t.max otherwise
-
Declaration
static pure nothrow @nogc bool
refersToParentDir
(const(char)*name
);Determine if path has a reference to parent directory.
Parameters
const(char)*
name
path
Return Value
true
if path contains '..' reference to parent directory -
Declaration
static nothrow int
exists
(const(char)*name
);
static nothrow intexists
(const(char)[]name
);Check if the file the
path
points toexists
Return Value
0 if it does not
exists
1 if itexists
and is not a directory 2 if itexists
and is a directory -
Declaration
static nothrow bool
ensurePathExists
(const(char)[]path
);
static nothrow boolensurePathExists
(const(char)*path
);Ensure that the provided
path
existsDiscussion
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.Parameters
const(char)[]
path
a
path
to a file or a directoryReturn Value
true
if 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 void
free
(const(char)*str
);Free memory allocated by FileName routines
-