D Programming Language 2.0

- Comments
- D
- Search
- Home

Last update Tue Feb 14 02:46:16 2012

# std.path

This module is used to manipulate path strings.

All functions, with the exception of expandTilde (and in some cases absolutePath and relativePath), are pure string manipulation functions; they don't depend on any state outside the program, nor do they perform any actual file system actions. This has the consequence that the module does not make any distinction between a path that points to a directory and a path that points to a file, and it does not know whether or not the object pointed to by the path actually exists in the file system. To differentiate between these cases, use std.file.isDir and std.file.exists.

Note that on Windows, both the backslash ('\') and the slash ('/') are in principle valid directory separators. This module treats them both on equal footing, but in cases where a new separator is added, a backslash will be used. Furthermore, the buildNormalizedPath function will replace all slashes with backslashes on that platform.

In general, the functions in this module assume that the input paths are well-formed. (That is, they should not contain invalid characters, they should follow the file system's path format, etc.) The result of calling a function on an ill-formed path is undefined. When there is a chance that a path or a file name is invalid (for instance, when it has been input by the user), it may sometimes be desirable to use the isValidFilename and isValidPath functions to check this.

Authors:
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu

License:
Boost License 1.0

Source:
std/path.d

string dirSeparator;
  String used to separate directory names in a path. Under POSIX this is a slash, under Windows a backslash.

string pathSeparator;
  Path separator string. A colon under POSIX, a semicolon under Windows.

pure nothrow @safe bool isDirSeparator(dchar c);
  Determine whether the given character is a directory separator.

  On Windows, this includes both '\' and '/'. On POSIX, it's just '/'.

enum CaseSensitive;
  This enum is used as a template argument to functions which compare file names, and determines whether the comparison is case sensitive or not.

  no
    File names are case insensitive

  yes
    File names are case sensitive

  osDefault
    The default (or most common) setting for the current platform. That is, no on Windows and Mac OS X, and yes on all POSIX systems except OS X (Linux, *BSD, etc.).

pure @trusted inout(C)[] baseName(C)(inout(C)[] path);
pure @safe inout(C)[] baseName(CaseSensitive cs = CaseSensitive.osDefault, C, C1)(inout(C)[] path, in C1[] suffix);
  Returns the name of a file, without any leading directory and with an optional suffix chopped off.

  If suffix is specified, it will be compared to path using filenameCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCmp documentation for details.

  Examples:

          assert (baseName("dir/file.ext")         == "file.ext");
          assert (baseName("dir/file.ext", ".ext") == "file");
          assert (baseName("dir/file.ext", ".xyz") == "file.ext");
          assert (baseName("dir/filename", "name") == "file");
          assert (baseName("dir/subdir/")          == "subdir");

          version (Windows)
          {
              assert (baseName(`d:file.ext`)      == "file.ext");
              assert (baseName(`d:\dir\file.ext`) == "file.ext");
          }

  Note:
  This function only strips away the specified suffix. If you want to remove the extension from a path, regardless of what the extension is, use stripExtension. If you want the filename without leading directories and without an extension, combine the functions like this:

          assert (baseName(stripExtension("dir/file.ext")) == "file");

  Standards:
  This function complies with the POSIX requirements for the 'basename' shell utility (with suitable adaptations for Windows paths).

C[] dirName(C)(C[] path);
  Returns the directory part of a path. On Windows, this includes the drive letter if present.

  Examples:

          assert (dirName("file")        == ".");
          assert (dirName("dir/file")    == "dir");
          assert (dirName("/file")       == "/");
          assert (dirName("dir/subdir/") == "dir");

          version (Windows)
          {
              assert (dirName("d:file")      == "d:");
              assert (dirName(`d:\dir\file`) == `d:\dir`);
              assert (dirName(`d:\file`)     == `d:\`);
              assert (dirName(`dir\subdir\`) == `dir`);
          }

  Standards:
  This function complies with the POSIX requirements for the 'dirname' shell utility (with suitable adaptations for Windows paths).

pure nothrow @safe inout(C)[] rootName(C)(inout(C)[] path);
  Returns the root directory of the specified path, or null if the path is not rooted.

  Examples:

          assert (rootName("foo") is null);
          assert (rootName("/foo") == "/");

          version (Windows)
          {
              assert (rootName(`\foo`) == `\`);
              assert (rootName(`c:\foo`) == `c:\`);
              assert (rootName(`\\server\share\foo`) == `\\server\share`);
          }

pure nothrow @safe inout(C)[] driveName(C)(inout(C)[] path);
  Returns the drive of a path, or null if the drive is not specified. In the case of UNC paths, the network share is returned.

  Always returns null on POSIX.

  Examples:

          version (Windows)
          {
              assert (driveName(`d:\file`) == "d:");
              assert (driveName(`\\server\share\file`) == `\\server\share`);
              assert (driveName(`dir\file`).empty);
          }

pure nothrow @safe inout(C)[] stripDrive(C)(inout(C)[] path);
  Strip the drive from a Windows path. On POSIX, this is a noop.

  Example:

          version (Windows)
          {
              assert (stripDrive(`d:\dir\file`) == `\dir\file`);
              assert (stripDrive(`\\server\share\dir\file`) == `\dir\file`);
          }

pure nothrow @safe inout(C)[] extension(C)(inout(C)[] path);
  Get the extension part of a file name, including the dot.

  If there is no extension, null is returned.

  Examples:

          assert (extension("file").empty);
          assert (extension("file.ext")       == ".ext");
          assert (extension("file.ext1.ext2") == ".ext2");
          assert (extension("file.")          == ".");
          assert (extension(".file").empty);
          assert (extension(".file.ext")      == ".ext");

pure nothrow @safe inout(C)[] stripExtension(C)(inout(C)[] path);
  Return the path with the extension stripped off.

  Examples:

          assert (stripExtension("file")           == "file");
          assert (stripExtension("file.ext")       == "file");
          assert (stripExtension("file.ext1.ext2") == "file.ext1");
          assert (stripExtension("file.")          == "file");
          assert (stripExtension(".file")          == ".file");
          assert (stripExtension(".file.ext")      == ".file");
          assert (stripExtension("dir/file.ext")   == "dir/file");

pure nothrow @trusted immutable(Unqual!(C1))[] setExtension(C1, C2)(in C1[] path, in C2[] ext);
pure nothrow @trusted immutable(C1)[] setExtension(C1, C2)(immutable(C1)[] path, const(C2)[] ext);
  Set the extension of a filename.

  If the filename already has an extension, it is replaced. If not, the extension is simply appended to the filename. Including the dot in the extension is optional.

  This function normally allocates a new string (the possible exception being case when path is immutable and doesn't already have an extension).

  Examples:

          assert (setExtension("file", "ext")      == "file.ext");
          assert (setExtension("file", ".ext")     == "file.ext");
          assert (setExtension("file.old", "new")  == "file.new");
          assert (setExtension("file.old", ".new") == "file.new");

pure @trusted immutable(Unqual!(C1))[] defaultExtension(C1, C2)(in C1[] path, in C2[] ext);
  Set the extension of a filename, but only if it doesn't already have one.

  Including the dot in the extension is optional.

  This function always allocates a new string, except in the case when path is immutable and already has an extension.

  Examples:

          assert (defaultExtension("file", "ext")      == "file.ext");
          assert (defaultExtension("file", ".ext")     == "file.ext");
          assert (defaultExtension("file.", "ext")     == "file.");
          assert (defaultExtension("file.old", "new")  == "file.old");
          assert (defaultExtension("file.old", ".new") == "file.old");

immutable(C)[] buildPath(C)(const(C[])[] paths...);
  Joins one or more path components.

  The given path components are concatenated with each other, and if necessary, directory separators are inserted between them. If any of the path components are rooted (see isRooted) the preceding path components will be dropped.

  Examples:

          version (Posix)
          {
              assert (buildPath("foo", "bar", "baz") == "foo/bar/baz");
              assert (buildPath("/foo/", "bar")      == "/foo/bar");
              assert (buildPath("/foo", "/bar")      == "/bar");
          }

          version (Windows)
          {
              assert (buildPath("foo", "bar", "baz") == `foo\bar\baz`);
              assert (buildPath(`c:\foo`, "bar")    == `c:\foo\bar`);
              assert (buildPath("foo", `d:\bar`)    == `d:\bar`);
              assert (buildPath("foo", `\bar`)      == `\bar`);
          }

pure nothrow @trusted immutable(C)[] buildNormalizedPath(C)(const(C[])[] paths...);
  Performs the same task as buildPath, while at the same time resolving current/parent directory symbols ("." and "..") and removing superfluous directory separators. On Windows, slashes are replaced with backslashes.

  Note that this function does not resolve symbolic links.

  Examples:

          version (Posix)
          {
              assert (buildNormalizedPath("/foo/./bar/..//baz/") == "/foo/baz");
              assert (buildNormalizedPath("../foo/.") == "../foo");
              assert (buildNormalizedPath("/foo", "bar/baz/") == "/foo/bar/baz");
              assert (buildNormalizedPath("/foo", "/bar/..", "baz") == "/baz");
              assert (buildNormalizedPath("foo/./bar", "../../", "../baz") == "../baz");
              assert (buildNormalizedPath("/foo/./bar", "../../baz") == "/baz");
          }

          version (Windows)
          {
              assert (buildNormalizedPath(`c:\foo\.\bar/..\\baz\`) == `c:\foo\baz`);
              assert (buildNormalizedPath(`..\foo\.`) == `..\foo`);
              assert (buildNormalizedPath(`c:\foo`, `bar\baz\`) == `c:\foo\bar\baz`);
              assert (buildNormalizedPath(`c:\foo`, `bar/..`) == `c:\foo`);
              assert (buildNormalizedPath(`\\server\share\foo`, `..\bar`) == `\\server\share\bar`);
          }

pure nothrow @safe auto pathSplitter(C)(const(C)[] path);
  Returns a bidirectional range that iterates over the elements of a path.

  Examples:

          assert (equal(pathSplitter("/"), ["/"]));
          assert (equal(pathSplitter("/foo/bar"), ["/", "foo", "bar"]));
          assert (equal(pathSplitter("//foo/bar"), ["//foo", "bar"]));
          assert (equal(pathSplitter("foo/../bar//./"), ["foo", "..", "bar", "."]));

          version (Windows)
          {
              assert (equal(pathSplitter(`foo\..\bar\/.\`), ["foo", "..", "bar", "."]));
              assert (equal(pathSplitter("c:"), ["c:"]));
              assert (equal(pathSplitter(`c:\foo\bar`), [`c:\`, "foo", "bar"]));
              assert (equal(pathSplitter(`c:foo\bar`), ["c:foo", "bar"]));
          }

pure nothrow @safe bool isRooted(C)(in const(C[]) path);
  Determines whether a path starts at a root directory.

  On POSIX, this function returns true if and only if the path starts with a slash (/).

          version (Posix)
          {
              assert (isRooted("/"));
              assert (isRooted("/foo"));
              assert (!isRooted("foo"));
              assert (!isRooted("../foo"));
          }

  On Windows, this function returns true if the path starts at the root directory of the current drive, of some other drive, or of a network drive.

          version (Windows)
          {
              assert (isRooted(`\`));
              assert (isRooted(`\foo`));
              assert (isRooted(`d:\foo`));
              assert (isRooted(`\\foo\bar`));
              assert (!isRooted("foo"));
              assert (!isRooted("d:foo"));
          }

pure nothrow @safe bool isAbsolute(C)(in const(C[]) path);
  Determines whether a path is absolute or not.

  Examples:
  On POSIX, an absolute path starts at the root directory. (In fact, isAbsolute is just an alias for isRooted.)

          version (Posix)
          {
              assert (isAbsolute("/"));
              assert (isAbsolute("/foo"));
              assert (!isAbsolute("foo"));
              assert (!isAbsolute("../foo"));
          }

  On Windows, an absolute path starts at the root directory of a specific drive. Hence, it must start with "d:\" or "d:/", where d is the drive letter. Alternatively, it may be a network path, i.e. a path starting with a double (back)slash.

          version (Windows)
          {
              assert (isAbsolute(`d:\`));
              assert (isAbsolute(`d:\foo`));
              assert (isAbsolute(`\\foo\bar`));
              assert (!isAbsolute(`\`));
              assert (!isAbsolute(`\foo`));
              assert (!isAbsolute("d:foo"));
          }

string absolutePath(string path, string base = getcwd());
  Translate path into an absolute path.

  This means:
  - If path is empty, return null.
  - If path is already absolute, return it.
  - Otherwise, append path to base and return the result. If base is not specified, the current working directory is used.

  Examples:

          version (Posix)
          {
              assert (absolutePath("some/file", "/foo/bar")  == "/foo/bar/some/file");
              assert (absolutePath("../file", "/foo/bar")    == "/foo/bar/../file");
              assert (absolutePath("/some/file", "/foo/bar") == "/some/file");
          }

          version (Windows)
          {
              assert (absolutePath(`some\file`, `c:\foo\bar`)    == `c:\foo\bar\some\file`);
              assert (absolutePath(`..\file`, `c:\foo\bar`)      == `c:\foo\bar\..\file`);
              assert (absolutePath(`c:\some\file`, `c:\foo\bar`) == `c:\some\file`);
          }

  Throws:
  Exception if the specified base directory is not absolute.

string relativePath(CaseSensitive cs = CaseSensitive.osDefault)(string path, string base = getcwd());
  Translate path into a relative path.

  The returned path is relative to base, which is by default taken to be the current working directory. If specified, base must be an absolute path, and it is always assumed to refer to a directory. If path and base refer to the same directory, the function returns ".".

  The following algorithm is used:
  1. If path is a relative directory, return it unaltered.
  2. Find a common root between path and base. If there is no common root, return path unaltered.
  3. Prepare a string with as many "../" or "..\" as necessary to reach the common root from base path.
  4. Append the remaining segments of path to the string and return.

  In the second step, path components are compared using filenameCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCmp documentation for details.

  Examples:

          assert (relativePath("foo") == "foo");

          version (Posix)
          {
              assert (relativePath("foo", "/bar") == "foo");
              assert (relativePath("/foo/bar", "/foo/bar") == ".");
              assert (relativePath("/foo/bar", "/foo/baz") == "../bar");
              assert (relativePath("/foo/bar/baz", "/foo/woo/wee") == "../../bar/baz");
              assert (relativePath("/foo/bar/baz", "/foo/bar") == "baz");
          }
          version (Windows)
          {
              assert (relativePath("foo", `c:\bar`) == "foo");
              assert (relativePath(`c:\foo\bar`, `c:\foo\bar`) == ".");
              assert (relativePath(`c:\foo\bar`, `c:\foo\baz`) == `..\bar`);
              assert (relativePath(`c:\foo\bar\baz`, `c:\foo\woo\wee`) == `..\..\bar\baz`);
              assert (relativePath(`c:\foo\bar\baz`, `c:\foo\bar`) == "baz");
              assert (relativePath(`c:\foo\bar`, `d:\foo`) == `c:\foo\bar`);
          }

  Throws:
  Exception if the specified base directory is not absolute.

pure nothrow @safe int filenameCharCmp(CaseSensitive cs = CaseSensitive.osDefault)(dchar a, dchar b);
  Compare filename characters and return < 0 if a < b, 0 if a == b and > 0 if a > b.

  This function can perform a case-sensitive or a case-insensitive comparison. This is controlled through the cs template parameter which, if not specified, is given by CaseSensitive.osDefault.

  On Windows, the backslash and slash characters ('\' and '/') are considered equal.

  Examples:

          assert (filenameCharCmp('a', 'a') == 0);
          assert (filenameCharCmp('a', 'b') < 0);
          assert (filenameCharCmp('b', 'a') > 0);

          version (linux)
          {
              // Same as calling filenameCharCmp!(CaseSensitive.yes)(a, b)
              assert (filenameCharCmp('A', 'a') < 0);
              assert (filenameCharCmp('a', 'A') > 0);
          }
          version (Windows)
          {
              // Same as calling filenameCharCmp!(CaseSensitive.no)(a, b)
              assert (filenameCharCmp('a', 'A') == 0);
              assert (filenameCharCmp('a', 'B') < 0);
              assert (filenameCharCmp('A', 'b') < 0);
          }

pure @safe int filenameCmp(CaseSensitive cs = CaseSensitive.osDefault, C1, C2)(const(C1)[] filename1, const(C2)[] filename2);
  Compare file names and return < 0 if filename1 < filename2, 0 if filename1 == filename2 and > 0 if filename1 > filename2.

  Individual characters are compared using filenameCharCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCharCmp documentation for details.

  Examples:

          assert (filenameCmp("abc", "abc") == 0);
          assert (filenameCmp("abc", "abd") < 0);
          assert (filenameCmp("abc", "abb") > 0);
          assert (filenameCmp("abc", "abcd") < 0);
          assert (filenameCmp("abcd", "abc") > 0);

          version (linux)
          {
              // Same as calling filenameCmp!(CaseSensitive.yes)(filename1, filename2)
              assert (filenameCmp("Abc", "abc") < 0);
              assert (filenameCmp("abc", "Abc") > 0);
          }
          version (Windows)
          {
              // Same as calling filenameCmp!(CaseSensitive.no)(filename1, filename2)
              assert (filenameCmp("Abc", "abc") == 0);
              assert (filenameCmp("abc", "Abc") == 0);
              assert (filenameCmp("Abc", "abD") < 0);
              assert (filenameCmp("abc", "AbB") > 0);
          }

pure nothrow @safe bool globMatch(CaseSensitive cs = CaseSensitive.osDefault, C)(const(C)[] path, const(C)[] pattern);
  Matches a pattern against a path.

  Some characters of pattern have a special meaning (they are meta-characters) and can't be escaped. These are:

  * | Matches 0 or more instances of any character.
  ? | Matches exactly one instance 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.
  {string1,string2,…} | Matches either of the specified strings.

  Individual characters are compared using filenameCharCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCharCmp documentation for details.

  Note that directory separators and dots don't stop a meta-character from matching further portions of the path.

  Returns:
  true if pattern matches path, false otherwise.

  See Also:
  Wikipedia: glob (programming)

  Examples:

          assert (globMatch("foo.bar", "*"));
          assert (globMatch("foo.bar", "*.*"));
          assert (globMatch(`foo/foo\bar`, "f*b*r"));
          assert (globMatch("foo.bar", "f???bar"));
          assert (globMatch("foo.bar", "[fg]???bar"));
          assert (globMatch("foo.bar", "[!gh]*bar"));
          assert (globMatch("bar.fooz", "bar.{foo,bif}z"));
          assert (globMatch("bar.bifz", "bar.{foo,bif}z"));

          version (Windows)
          {
              // Same as calling globMatch!(CaseSensitive.no)(path, pattern)
              assert (globMatch("foo", "Foo"));
              assert (globMatch("Goo.bar", "[fg]???bar"));
          }
          version (linux)
          {
              // Same as calling globMatch!(CaseSensitive.yes)(path, pattern)
              assert (!globMatch("foo", "Foo"));
              assert (!globMatch("Goo.bar", "[fg]???bar"));
          }

pure nothrow @safe bool isValidFilename(C)(in C[] filename);
  Checks that the given file or directory name is valid.

  This function returns true if and only if filename is not empty, not too long, and does not contain invalid characters.

  The maximum length of filename is given by the constant core.stdc.stdio.FILENAME_MAX. (On Windows, this number is defined as the maximum number of UTF-16 code points, and the test will therefore only yield strictly correct results when filename is a string of wchars.)

  On Windows, the following criteria must be satisfied (source):
  - filename must not contain any characters whose integer representation is in the range 0-31.
  - filename must not contain any of the following reserved characters: <>:"/\|?*
  - filename may not end with a space (' ') or a period ('.').

  On POSIX, filename may not contain a forward slash ('/') or the null character ('\0').

pure nothrow @safe bool isValidPath(C)(in C[] path);
  Checks whether path is a valid path.

  Generally, this function checks that path is not empty, and that each component of the path either satisfies isValidFilename or is equal to "." or "..". It does not check whether the path points to an existing file or directory; use std.file.exists for this purpose.

  On Windows, some special rules apply:
  - If the second character of path is a colon (':'), the first character is interpreted as a drive letter, and must be in the range A-Z (case insensitive).
  - If path is on the form `\\server\share\...` (UNC path), isValidFilename is applied to server and share as well.
  - If path starts with `\\?\` (long UNC path), the only requirement for the rest of the string is that it does not contain the null character.
  - If path starts with `\\.\` (Win32 device namespace) this function returns false; such paths are beyond the scope of this module.

string expandTilde(string inputPath);
  Performs tilde expansion in paths on POSIX systems. On Windows, this function does nothing.

  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.

  Examples:

          void processFile(string path)
          {
              // Allow calling this function with paths such as ~/foo
              auto fullPath = expandTilde(path);
              ...
          }

int fcmp(alias pred = "a < b", S1, S2)(S1 s1, S2 s2);
  Scheduled for deprecation in February 2012. Please use filenameCmp instead.

  Compare file names.

  Returns:

  < 0 | filename1 < filename2
  = 0 | filename1 == filename2
  > 0 | filename1 > filename2

string getExt()(string fullname);
  Scheduled for deprecation in February 2012. Please use extension instead.

  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(Windows)
       {
           getExt(r"d:\path\foo.bat") // "bat"
           getExt(r"d:\path.two\bar") // null
       }
       version(Posix)
       {
           getExt(r"/home/user.name/bar.")  // ""
           getExt(r"d:\\path.two\\bar")     // "two\\bar"
           getExt(r"/home/user/.resource")  // "resource"
       }

string getName()(string fullname);
  Scheduled for deprecation in February 2012. Please use stripExtension instead.

  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(Windows)
       {
           getName(r"d:\path\foo.bat") => "d:\path\foo"
           getName(r"d:\path.two\bar") => null
       }
       version(Posix)
       {
           getName("/home/user.name/bar.")  => "/home/user.name/bar"
           getName(r"d:\path.two\bar") => "d:\path"
           getName("/home/user/.resource") => "/home/user/"
       }

Char[] basename(Char, ExtChar = immutable(char))(Char[] fullname, ExtChar[] extension = null);
  Scheduled for deprecation in February 2012. Please use baseName instead.

  Extracts the base name of a path and optionally chops off a specific suffix.

  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. After the search has ended, keep the portion to the right of the separator if found, or the entire fullname otherwise. If the kept portion has suffix extension, remove that suffix. Return the remaining string.

  Returns:
  The portion of fullname left after the path part and the extension part, if any, have been removed.

  Throws:
  Nothing.

  Examples:

       version(Windows)
       {
           basename(r"d:\path\foo.bat") => "foo.bat"
           basename(r"d:\path\foo", ".bat") => "foo"
       }
       version(Posix)
       {
           basename("/home/user.name/bar.")  => "bar."
           basename("/home/user.name/bar.", ".")  => "bar"
       }

Char[] dirname(Char)(Char[] fullname);
  Scheduled for deprecation in February 2012. Please use dirName instead.

  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 without any trailing path separators are returned. Otherwise, "." is returned.

  The found path separator will be included in the returned string if and only if it represents the root.

  Throws:
  Nothing.

  Examples:

       version(Windows)
       {
           assert(dirname(r"d:\path\foo.bat") == r"d:\path");
           assert(dirname(r"d:\path") == r"d:\");
           assert(dirname("d:foo.bat") == "d:.");
           assert(dirname("foo.bat") == ".");
       }
       version(Posix)
       {
           assert(dirname("/home/user") == "/home");
           assert(dirname("/home") == "/");
           assert(dirname("user") == ".");
       }

Char[] getDrive(Char)(Char[] fullname);
  Scheduled for deprecation in February 2012. Please use driveName instead.

  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:"

string defaultExt()(string filename, string ext);
  Scheduled for deprecation in February 2012. Please use defaultExtension instead.

  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"

string addExt()(string filename, string ext);
  Scheduled for deprecation in February 2012. Please use setExtension instead.

  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"

bool isabs()(in char[] path);
  Scheduled for deprecation in February 2012. Please use isAbsolute instead.

  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(Windows)
       {
           isabs(r"relative\path") => 0
           isabs(r"\relative\path") => 0
           isabs(r"d:\absolute") => 1
       }
       version(Posix)
       {
           isabs("/home/user") => 1
           isabs("foo") => 0
       }

string rel2abs()(string path);
  Scheduled for deprecation in February 2012. Please use absolutePath instead.

  Converts a relative path into an absolute path.

string join()(const(char)[] p1, const(char)[] p2, const(char[])[] more...);
  Scheduled for deprecation in February 2012. Please use buildPath instead.

  Joins two or more path components.

  If p1 doesn't have a trailing path separator, one will be appended to it before concatenating p2.

  Returns:
  p1 ~ p2. However, if p2 is an absolute path, only p2 will be returned.

  Throws:
  Nothing.

  Examples:

       version(Windows)
       {
           join(r"c:\foo", "bar") => r"c:\foo\bar"
           join("foo", r"d:\bar") => r"d:\bar"
       }
       version(Posix)
       {
           join("/foo/", "bar") => "/foo/bar"
           join("/foo", "/bar") => "/bar"
       }

bool fncharmatch()(dchar c1, dchar c2);
  Scheduled for deprecation in February 2012. Please use filenameCharCmp instead.

  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(Windows)
       {
           fncharmatch('a', 'b') => 0
           fncharmatch('A', 'a') => 1
       }
       version(Posix)
       {
           fncharmatch('a', 'b') => 0
           fncharmatch('A', 'a') => 0
       }

bool fnmatch()(const(char)[] filename, const(char)[] pattern);
  Scheduled for deprecation in February 2012. Please use globMatch instead.

  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(Windows)
       {
           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(Posix)
       {
           fnmatch("Go*.bar", "[fg]???bar") => 0
           fnmatch("/foo*home/bar", "?foo*bar") => 1
           fnmatch("foobar", "foo?bar") => 1
       }

Copyright (c) 2000–2011, the authors. All rights reserved. | Page generated by Ddoc.