A path name.
A slice of path or ".".
assert(dirName("") == "."); assert(dirName("file"w) == "."); assert(dirName("dir/"d) == "."); assert(dirName("dir///") == "."); assert(dirName("dir/file"w.dup) == "dir"); assert(dirName("dir///file"d.dup) == "dir"); assert(dirName("dir/subdir/") == "dir"); assert(dirName("/dir/file"w) == "/dir"); assert(dirName("/file"d) == "/"); assert(dirName("/") == "/"); assert(dirName("///") == "/"); version (Windows) { assert(dirName(`dir\`) == `.`); assert(dirName(`dir\\\`) == `.`); assert(dirName(`dir\file`) == `dir`); assert(dirName(`dir\\\file`) == `dir`); assert(dirName(`dir\subdir\`) == `dir`); assert(dirName(`\dir\file`) == `\dir`); assert(dirName(`\file`) == `\`); assert(dirName(`\`) == `\`); assert(dirName(`\\\`) == `\`); assert(dirName(`d:`) == `d:`); assert(dirName(`d:file`) == `d:`); assert(dirName(`d:\`) == `d:\`); assert(dirName(`d:\file`) == `d:\`); assert(dirName(`d:\dir\file`) == `d:\dir`); assert(dirName(`\\server\share\dir\file`) == `\\server\share\dir`); assert(dirName(`\\server\share\file`) == `\\server\share`); assert(dirName(`\\server\share\`) == `\\server\share`); assert(dirName(`\\server\share`) == `\\server\share`); }
This function complies with the POSIX requirements for the 'dirname' shell utility (with suitable adaptations for Windows paths).
Returns the parent directory of path. On Windows, this includes the drive letter if present. If path is a relative path and the parent directory is the current working directory, returns ".".