Path

Path - struct that represents single path object, and provides convenient interface to deal with filesystem paths.

struct Path {}

Constructors

this
this(string path)

Main constructor to build new Path from string

this
this(string[] segments)

Constructor that allows to build path from segments

Members

Functions

appendFile
void appendFile(void[] buffer)

Append data to file as is

baseName
string baseName()

Returns base name of current path

chdir
void chdir()

Change current working directory to this.

chdir
void chdir(string[] sub_path)
void chdir(Path sub_path)

Change current working directory to path inside currect path

copyFileTo
void copyFileTo(Path dest, bool rewrite)

Copy single file to destination. If destination does not exists, then file will be copied exactly to that path. If destination already exists and it is directory, then method will try to copy file inside that directory with same name. If destination already exists and it is file, then depending on rewrite param file will be owerwritten or PathException will be thrown.

copyTo
void copyTo(Path dest)
void copyTo(string dest)

Copy file or directory to destination If source is a file, then copyFileTo will be use to copy it. If source is a directory, then more complex logic will be applied:

execute
auto execute(string[] args, string[string] env, Path workDir, std.process.Config config, size_t maxOutput)

Execute the file pointed by path

execute
auto execute(string[] args, string[string] env, Nullable!Path workDir, std.process.Config config, size_t maxOutput)

Execute the file pointed by path

exists
bool exists()

Check if path exists

expandTilde
Path expandTilde()

Expand tilde (~) in current path.

extension
string extension()

Returns extension for current path

getAttributes
auto getAttributes()

Get attributes of the path

getSize
ulong getSize()

Return size of file specified by path

glob
auto glob(string pattern, SpanMode mode, bool followSymlink)

Search files that match provided glob pattern inside current path.

hasAttributes
bool hasAttributes(uint attributes)

Check if file has numeric attributes. This method check if all bits specified by param 'attributes' are set.

isAbsolute
bool isAbsolute()

Check if path is absolute

isDir
bool isDir()

Determine if path is directory.

isFile
bool isFile()

Determine if path is file.

isInside
bool isInside(Path other)

Check if current path is inside other path

isRoot
bool isRoot()

Check if current path is root (does not have parent)

isRooted
bool isRooted()

Check if path starts at root directory (or drive letter)

isSymlink
bool isSymlink()

Determine if path is symlink

isValid
bool isValid()

Check if path is valid.

join
auto join(string[] segments)
Path join(Path[] segments)

Join multiple path segments and return single path.

matchGlob
bool matchGlob(string pattern)

Check if path matches specified glob pattern. See Also: - https://en.wikipedia.org/wiki/Glob_%28programming%29 - https://dlang.org/phobos/std_path.html#globMatch

mkdir
void mkdir(bool recursive)

Create directory by this path

normalize
Path normalize()

Normalize path.

opCmp
int opCmp(Path other)

Override comparison operators to use OS-specific case-sensitivity rules. They could be used for sorting of path array for example.

opEquals
bool opEquals(Path other)

Override equality comparison operators

openFile
std.stdio.File openFile(string openMode)

Open file and return std.stdio.File struct with opened file

parent
Path parent()

determine parent path of this path

readFile
auto readFile(size_t upTo)

Read entire contents of file name and returns it as an untyped array. If the file size is larger than upTo, only upTo bytes are _read.

readFileText
auto readFileText()

Read text content of the file. Technicall just a call to std.file.readText.

readLink
Path readLink()

Resolve link and return real path. Available only for posix systems. If path is not symlink, then return it unchanged

realPath
Path realPath()

Get real path with all symlinks resolved. If any segment of path is symlink, then this method will automatically resolve that segment.

relativeTo
Path relativeTo(Path base)
Path relativeTo(string base)

Return this path as relative to base

remove
void remove()

Remove file or directory referenced by this path. This operation is recursive, so if path references to a direcotry, then directory itself and all content inside referenced dir will be removed

rename
void rename(Path to)
void rename(string to)

Rename current path.

searchFileUp
Nullable!Path searchFileUp(string file_name)
Nullable!Path searchFileUp(Path search_path)

Search file by name in current directory and parent directories. Usually, this could be used to find project config, when current directory is somewhere inside project.

segments
auto segments()

Split path on segments. Under the hood, this method uses std.path.pathSplitter

setAttributes
void setAttributes(uint attributes)

Set attributes of the path

symlink
void symlink(Path dest)

Create symlink for this file in dest path.

toAbsolute
Path toAbsolute()

Convert path to absolute path.

toHash
size_t toHash()

Compute hash of the Path to be able to use it as key in asociative arrays.

toString
string toString()

Return path as string

walk
auto walk(SpanMode mode, bool followSymlink)

Iterate over all files and directories inside path;

walkBreadth
auto walkBreadth(bool followSymlink)

Just an alias for walk(SpanModel.breadth)

walkDepth
auto walkDepth(bool followSymlink)

Just an alias for walk(SpanModel.depth)

writeFile
void writeFile(void[] buffer)

Write data to file as is

Static functions

current
Path current()

Return current path (as absolute path)

Meta