D
Language
Phobos
Comparisons
object
std
std.base64
std.boxer
std.compiler
std.conv
std.cover
std.ctype
std.date
std.demangle
std.file
std.format
std.gc
std.intrinsic
std.math
std.md5
std.mmfile
std.openrj
std.outbuffer
std.path
std.process
std.random
std.recls
std.regexp
std.socket
std.socketstream
std.stdint
std.stdio
std.cstream
std.stream
std.string
std.system
std.thread
std.uri
std.utf
std.zip
std.zlib
std.c.fenv
std.c.math
std.c.process
std.c.stdarg
std.c.stddef
std.c.stdio
std.c.stdlib
std.c.string
std.c.time
std.c.wcharh
std.windows.charset
std.windows
std.linux
std.c.windows
std.c.linux
|
std.path
- const char[1] sep;
- String used to separate directory names in a path. Under
Windows this is a backslash, under Linux a slash.
- const char[1] altsep;
- Alternate version of sep[] used in Windows (a slash). Under
Linux this is empty.
- const char[1] pathsep;
- Path separator string. A semi colon under Windows, a colon
under Linux.
- const char[2] linesep;
- String used to separate lines.
String used to separate lines, \r\n under Windows and \n
under Linux.
String used to separate lines.
- const char[1] curdir;
- String representing the current directory.
- const char[2] pardir;
- String representing the parent directory.
- char[] getExt(char[] fullname);
- Extracts the extension from a filename or path.
This function will search fullname from the end until the
first dot, path separator or first character of fullname is
reached. Under Windows, the drive letter separator (colon)
also terminates the search.
Returns:
If a dot was found, characters to its right are
returned. If a path separator was found, or fullname didn't
contain any dots or path separators, returns null.
Throws:
Nothing.
Examples:
version(Win32)
{
getExt(r"d:\path\foo.bat") // "bat"
getExt(r"d:\path.two\bar") // null
}
version(linux)
{
getExt(r"/home/user.name/bar.") // ""
getExt(r"d:\\path.two\\bar") // "two\\bar"
getExt(r"/home/user/.resource") // "resource"
}
- char[] getName(char[] fullname);
- Returns the extensionless version of a filename or path.
This function will search fullname from the end until the
first dot, path separator or first character of fullname is
reached. Under Windows, the drive letter separator (colon)
also terminates the search.
Returns:
If a dot was found, characters to its left are
returned. If a path separator was found, or fullname didn't
contain any dots or path separators, returns null.
Throws:
Nothing.
Examples:
version(Win32)
{
getName(r"d:\path\foo.bat") => "d:\path\foo"
getName(r"d:\path.two\bar") => null
}
version(linux)
{
getName("/home/user.name/bar.") => "/home/user.name/bar"
getName(r"d:\path.two\bar") => "d:\path"
getName("/home/user/.resource") => "/home/user/"
}
- char[] getBaseName(char[] fullname);
- Extracts the base name of a path.
This function will search fullname from the end until the
first path separator or first character of fullname is
reached. Under Windows, the drive letter separator (colon)
also terminates the search.
Returns:
If a path separator was found, all the characters to its
right are returned. Otherwise, fullname is returned.
Throws:
Nothing.
Examples:
version(Win32)
{
getBaseName(r"d:\path\foo.bat") => "foo.bat"
}
version(linux)
{
getBaseName("/home/user.name/bar.") => "bar."
}
- char[] getDirName(char[] fullname);
- Extracts the directory part of a path.
This function will search fullname from the end until the
first path separator or first character of fullname is
reached. Under Windows, the drive letter separator (colon)
also terminates the search.
Returns:
If a path separator was found, all the characters to its
left are returned. Otherwise, fullname is returned.
Under Windows, the found path separator will be included in the
returned string if it is preceeded by a colon.
Throws:
Nothing.
Examples:
version(Win32)
{
getDirName(r"d:\path\foo.bat") => "d:\path"
getDirName(getDirName(r"d:\path\foo.bat")) => "d:\"
}
version(linux)
{
getDirName(")/home/user" => "/home"
getDirName(getDirName(")/home/user") => ""
}
- char[] getDrive(char[] fullname);
- Extracts the drive letter of a path.
This function will search fullname for a colon from the beginning.
Returns:
If a colon is found, all the characters to its left
plus the colon are returned. Otherwise, null is returned.
Under Linux, this function always returns null immediately.
Throws:
Nothing.
Examples:
getDrive(r"d:\path\foo.bat") => "d:"
- char[] defaultExt(char[] filename, char[] ext);
- Appends a default extension to a filename.
This function first searches filename for an extension and
appends ext if there is none. ext should not have any leading
dots, one will be inserted between filename and ext if filename
doesn't already end with one.
Returns:
filename if it contains an extension, otherwise filename
+ ext.
Throws:
Nothing.
Examples:
defaultExt("foo.txt", "raw") => "foo.txt"
defaultExt("foo.", "raw") => "foo.raw"
defaultExt("bar", "raw") => "bar.raw"
- char[] addExt(char[] filename, char[] ext);
- Adds or replaces an extension to a filename.
This function first searches filename for an extension and
replaces it with ext if found. If there is no extension, ext
will be appended. ext should not have any leading dots, one will
be inserted between filename and ext if filename doesn't already
end with one.
Returns:
filename + ext if filename is extensionless. Otherwise
strips filename's extension off, appends ext and returns the
result.
Throws:
Nothing.
Examples:
addExt("foo.txt", "raw") => "foo.raw"
addExt("foo.", "raw") => "foo.raw"
addExt("bar", "raw") => "bar.raw"
- int isabs(char[] path);
- Checks if path is absolute.
Returns:
non-zero if the path starts from the root directory (Linux) or
drive letter and root directory (Windows),
zero otherwise.
Throws:
Nothing.
Examples:
version(Win32)
{
isabs(r"relative\path") => 0
isabs(r"\relative\path") => 0
isabs(r"d:\absolute") => 1
}
version(linux)
{
isabs("/home/user") => 1
isabs("foo") => 0
}
- char[] join(char[] p1, char[] p2);
- Joins two path components.
If p1 doesn't have a trailing path separator, one will be appended
to it before concatting p2.
Returns:
p1 ~ p2. However, if p2 is an absolute path, only p2
will be returned.
Throws:
Nothing.
Examples:
version(Win32)
{
join(r"c:\foo", "bar") => "c:\foo\bar"
join("foo", r"d:\bar") => "d:\bar"
}
version(linux)
{
join("/foo/", "bar") => "/foo/bar"
join("/foo", "/bar") => "/bar"
}
- int fncharmatch(dchar c1, dchar c2);
- Matches filename characters.
Under Windows, the comparison is done ignoring case. Under Linux
an exact match is performed.
Returns:
non zero if c1 matches c2, zero otherwise.
Throws:
Nothing.
Examples:
version(Win32)
{
fncharmatch('a', 'b') => 0
fncharmatch('A', 'a') => 1
}
version(linux)
{
fncharmatch('a', 'b') => 0
fncharmatch('A', 'a') => 0
}
- int fnmatch(char[] filename, char[] pattern);
- Matches a pattern against a filename.
Some characters of pattern have special a meaning (they are
meta-characters) and can't be escaped. These are:
* |
Matches 0 or more instances of any character. |
? |
Matches exactly one instances of any character. |
[chars] |
Matches one instance of any character that appears
between the brackets. |
[!chars] |
Matches one instance of any character that does not appear
between the brackets after the exclamation mark. |
Internally individual character comparisons are done calling
fncharmatch(), so its rules apply here too. Note that path
separators and dots don't stop a meta-character from matching
further portions of the filename.
Returns:
non zero if pattern matches filename, zero otherwise.
See Also:
fncharmatch().
Throws:
Nothing.
Examples:
version(Win32)
{
fnmatch("foo.bar", "*") => 1
fnmatch(r"foo/foo\bar", "f*b*r") => 1
fnmatch("foo.bar", "f?bar") => 0
fnmatch("Goo.bar", "[fg]???bar") => 1
fnmatch(r"d:\foo\bar", "d*foo?bar") => 1
}
version(linux)
{
fnmatch("Go*.bar", "[fg]???bar") => 0
fnmatch("/foo*home/bar", "?foo*bar") => 1
fnmatch("foobar", "foo?bar") => 1
}
- char[] expandTilde(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.
For Windows, expandTilde() merely returns its argument inputPath.
Throws:
std.OutOfMemory if there is not enough memory to perform
the database lookup for the ~user syntax.
Examples:
import std.path;
void process_file(char[] filename)
{
char[] path = expandTilde(filename);
...
}
import std.path;
const char[] RESOURCE_DIR_TEMPLATE = "~/.applicationrc";
char[] RESOURCE_DIR; // This gets expanded in main().
int main(char[][] args)
{
RESOURCE_DIR = expandTilde(RESOURCE_DIR_TEMPLATE);
...
}
Version:
Available since v0.143.
Authors:
Grzegorz Adam Hankiewicz, Thomas Kühne.
|