NiceIO A filesystem path. The path can be absolute or relative; the entity it refers to could be a file or a directory, and may or may not actually exist in the filesystem. Create a new NPath. The path that this NPath should represent. Create a new NPath by appending a path fragment. The path fragment to append. This can be a filename, or a whole relative path. A new NPath which is the existing path with the fragment appended. Create a new NPath by appending two path fragments, one after the other. The first path fragment to append. The second path fragment to append. A new NPath which is the existing path with the first fragment appended, then the second fragment appended. Create a new NPath by appending a path fragment. The path fragment to append. A new NPath which is the existing path with the fragment appended. Create a new NPath by appending multiple path fragments. The path fragments to append, in order. A new NPath which is this existing path with all the supplied path fragments appended, in order. The parent path fragment (i.e. the directory) of the path. Create a new NPath by computing the existing path relative to some other base path. The base path that the result should be relative to. A new NPath, which refers to the same target as the existing path, but is described relative to the given base path. Create an NPath by changing the extension of this one. The new extension to use. Starting it with a "." character is optional. If you pass an empty string, the resulting path will have the extension stripped entirely, including the dot character. A new NPath which is the existing path but with the new extension at the end. Whether this path is relative (i.e. not absolute) or not. The name of the file or directory given at the end of this path, including any extension. The name of the file or directory given at the end of this path, excluding the extension. Determines whether the given path is, or is a child of, a directory with the given name. The name of the directory to search for. True if the path describes a file/directory that is or is a child of a directory with the given name; false otherwise. The depth of the path, determined by the number of path separators present. Tests whether the path is the current directory string ".". Tests whether the path exists. An optional path fragment to append before testing. True if the path (with optional appended fragment) exists, false otherwise. Tests whether the path exists and is a directory. An optional path fragment to append before testing. True if the path (with optional appended fragment) exists and is a directory, false otherwise. Tests whether the path exists and is a file. An optional path fragment to append before testing. True if the path (with optional appended fragment) exists and is a file, false otherwise. The extension of the file, excluding the initial "." character. UNC server name of the path, if present. Null if not present. The Windows drive letter of the path, if present. Null if not present. Provides a quoted version of the path as a string, with the requested path separator type. The path separator to use. See the SlashMode enum for an explanation of the values. Defaults to SlashMode.Forward. The path, with the requested path separator type, in quotes. Convert this path to a string, using forward slashes as path separators. The string representation of this path. Convert this path to a string, using the requested path separator type. The path separator type to use. See SlashMode for possible values. The string representation of this path. Checks if this NPath represents the same path as another object. The object to compare to. True if this NPath represents the same path as the other object; false if it does not, if the other object is not an NPath, or is null. Checks if this NPath is equal to another NPath. The path to compare to. True if this NPath represents the same path as the other NPath; false otherwise. Note that the comparison requires that the paths are the same, not just that the targets are the same; "foo/bar" and "foo/baz/../bar" refer to the same target but will not be treated as equal by this comparison. However, this comparison will ignore case differences when the current operating system does not use case-sensitive filesystems. Compare two NPaths for equality. The first NPath to compare. The second NPath to compare. True if the NPaths are both equal (or both null), false otherwise. See Equals. Get an appropriate hash value for this NPath. A hash value for this NPath. Compare this NPath to another NPath, returning a value that can be used to sort the two objects in a stable order. The object to compare to. Note that this object must be castable to NPath. A value that indicates the relative order of the two objects. The return value has these meanings: ValueMeaning Less than zeroThis instance precedes obj in the sort order. ZeroThis instance occurs in the same position as obj in the sort order. Greater than zeroThis instance follows obj in the sort order. Compare two NPaths for inequality. The first NPath to compare. The second NPath to compare. True if the NPaths are not equal, false otherwise. Tests whether this NPath has the provided extension. The extension to test for. True if this NPath has has the provided extension. False otherwise. The extension "*" is special, and will return true for all paths if specified. Tests whether this NPath has one of the provided extensions, or if no extensions are provided, whether it has any extension at all. The possible extensions to test for. True if this NPath has one of the provided extensions; or, if no extensions are provided, true if this NPath has an extension. False otherwise. The extension "*" is special, and will return true for all paths if specified. Whether this path is rooted or not (begins with a slash character or drive specifier). Whether this path starts with an UNC path prefix "\\" or not. Find all files within this path that match the given filter. The filter to match against the names of files. Wildcards can be included. If true, search recursively inside subdirectories of this path; if false, search only for files that are immediate children of this path. Defaults to false. An array of files that were found. Find all files within this path. If true, search recursively inside subdirectories of this path; if false, search only for files that are immediate children of this path. Defaults to false. An array of files that were found. Find all files within this path that have one of the provided extensions. The extensions to search for. If true, search recursively inside subdirectories of this path; if false, search only for files that are immediate children of this path. Defaults to false. An array of files that were found. Find all files or directories within this path that match the given filter. The filter to match against the names of files and directories. Wildcards can be included. If true, search recursively inside subdirectories of this path; if false, search only for files and directories that are immediate children of this path. Defaults to false. An array of files and directories that were found. Find all files and directories within this path. If true, search recursively inside subdirectories of this path; if false, search only for files and directories that are immediate children of this path. Defaults to false. An array of files and directories that were found. Find all directories within this path that match the given filter. The filter to match against the names of directories. Wildcards can be included. If true, search recursively inside subdirectories of this path; if false, search only for directories that are immediate children of this path. Defaults to false. An array of directories that were found. Find all directories within this path. If true, search recursively inside subdirectories of this path; if false, search only for directories that are immediate children of this path. Defaults to false. An array of directories that were found. Create an empty file at this path. This NPath, for chaining further operations. If a file already exists at this path, it will be overwritten. Append the given path fragment to this path, and create an empty file there. The path fragment to append. The path to the created file, for chaining further operations. If a file already exists at that path, it will be overwritten. Create this path as a directory if it does not already exist. This NPath, for chaining further operations. This is identical to , except that EnsureDirectoryExists triggers "Stat" callbacks and this doesn't. Append the given path fragment to this path, and create it as a directory if it does not already exist. The path fragment to append. The path to the created directory, for chaining further operations. Create this path as a symbolic link to another file or directory. The path that this path should be a symbolic link to. Can be relative or absolute. Specifies whether this link is to a file or to a directory (required on Windows). Defaults to file. The path to the created symbolic link, for chaining further operations. Checks whether the entity referred to by this path is a symbolic link. Copy this NPath to the given destination. The path to copy to. The path to the copied result, for chaining further operations. Copy this NPath to the given destination, applying a filter function to decide which files are copied. The path to copy to. The filter function. Each candidate file is passed to this function; if the function returns true, the file will be copied, otherwise it will not. Create a new NPath by converting this path into an absolute representation. Optional base to use as a root for relative paths. Deletes the file or directory referred to by the NPath. The deletion mode to use, see DeleteMode. Defaults to DeleteMode.Normal. The path does not exist. See also DeleteIfExists. Deletes the file or directory referred to by the NPath, if it exists. The deletion mode to use, see DeleteMode. Defaults to DeleteMode.Normal. This NPath, for chaining further operations. Deletes all files and directories inside the directory referred to by this NPath. This NPath, for chaining further operations. This NPath refers to a file, rather than a directory. Create a temporary directory in the system temporary location and return the NPath of it. A prefix to use for the name of the temporary directory. A new NPath which targets the newly created temporary directory. Move the file or directory targetted by this NPath to a new location. The destination for the move. An NPath representing the newly moved file or directory. The current directory in use by the process. Note that every read from this property will result in an operating system query, unless WithFrozenCurrentDirectory is used. Temporarily change the current directory for the process. The new directory to set as the current directory. A token representing the change in current directory. When this is disposed, the current directory will be returned to its previous value. The usual usage pattern is to capture the token with a using statement, such that it is automatically disposed of when the using block exits. The current user's home directory. The system temporary directory. Append an optional path fragment to this NPath, then create it as a directory if it does not already exist. The path fragment to append. The path to the directory that is now guaranteed to exist. This is identical to , except that this triggers "Stat" callbacks and CreateDirectory doesn't. Create the parent directory of this NPath if it does not already exist. This NPath, for chaining further operations. Throw an exception if this path does not exist as a file. This path, in order to chain further operations. The path does not exist, or is not a file. Throw an exception if this directory does not exist. This path, in order to chain further operations. The path does not exist, or is not a directory. Check if this path is a child of the given path hierarchy root (i.e. is a file or directory that is inside the given hierachy root directory or one of its descendent directories). The path hierarchy root to check. True if this path is a child of the given root path, false otherwise. Check if this path is a child of the given path hierarchy root (i.e. is a file or directory that is inside the given hierachy root directory or one of its descendent directories), or is equal to it. The path hierarchy root to check. True if this path is equal to or is a child of the given root path, false otherwise. Return each parent directory of this path, starting with the immediate parent, then that directory's parent, and so on, until the root of the path is reached. Search all parent directories of this path for one that contains a file or directory with the given name. The name of the file or directory to search for. The path to the parent directory that contains the file or directory, or null if none of the parents contained a file or directory with the requested name. Open this path as a text file, write the given string to it, then close the file. The string to write to the text file. The path to this file, for use in chaining further operations. Open this file as a text file, and replace the contents with the provided string, if they do not already match. Then close the file. The string to replace the file's contents with. The path to this file, for use in chaining further operations. Note that if the contents of the file already match the provided string, the file is not modified - this includes not modifying the file's "last written" timestamp. Open this path as a file, write the given bytes to it, then close the file. The bytes to write to the file. The path to this file, for use in chaining further operations. Opens a text file, reads all the text in the file into a single string, then closes the file. The contents of the text file, as a single string. Opens a file, reads all the bytes in the file, then closes the file. The contents of the file, as a bytes array. Opens a text file, writes all entries of a string array as separate lines into the file, then closes the file. The entries to write into the file as separate lines. The path to this file. Opens a text file, reads all lines of the file into a string array, and then closes the file. A string array containing all lines of the file. Copy all files in this NPath to the given destination directory. The directory to copy the files to. If true, files inside subdirectories of this NPath will also be copied. If false, only immediate child files of this NPath will be copied. An optional predicate function that can be used to filter files. It is passed each source file path in turn, and if it returns true, the file is copied; otherwise, the file is not copied. The paths to all the newly copied files. Note that the directory structure of the files relative to this NPath will be preserved within the target directory. Move all files in this NPath to the given destination directory. The directory to move the files to. If true, files inside subdirectories of this NPath will also be moved. If false, only immediate child files of this NPath will be moved. An optional predicate function that can be used to filter files. It is passed each source file path in turn, and if it returns true, the file is moved; otherwise, the file is not moved. The paths to all the newly moved files. Note that the directory structure of the files relative to this NPath will be preserved within the target directory. Implicitly construct a new NPath from a string. The string to construct the new NPath from. Set the last time the file was written to, in UTC. The last time the file was written to, in UTC. This is set automatically by the OS when the file is modified, but it can sometimes be useful to explicitly update the timestamp without modifying the file contents. Get the last time the file was written to, in UTC. The last time the file was written to, in UTC. Get the file length in bytes. The file length in bytes. The filesystem attributes of the given file, assuming it exists. Note that when you set this property, the OS may still modify the the actual attributes of the file beyond what you requested, so setting and then getting the property is not guaranteed to roundtrip the value. Note also that some attributes (e.g. FileAttributes.Hidden) are not supported on every OS, and may throw exceptions or simply be ignored. Until .Dispose is invoked on the returnvalue, makes all NPath's on this thread use the provided filesystem implementation for all filesystem access. An object you can invoke .Dispose() on, which will make all NPath filesystem operations stop using the provided filesystem Lets the currently active filesystem resolve the path. Shorthand for .ResolveWithFileSystem.InQuotes() Abstract baseclass you can use to plug in different underlying filesystem behaviour for NPath to operate on The currently active filesystem for NPath operations. Set this using NPath.WithFileSystem() If your filesystem does any kind of redirection or other magic, Resolve() is required to return the path that can be used against the raw lowlevel filesystem of the OS. The path to resolve The resolved path that is valid to use against the OS's real filesystem A Filesystem that forwards all calls to another filesytem. Derive your own filesystem from this if you only want to change the behaviour of a few methods. The filesystem all methods will be forwarded to Constructor the filesystem all calls will be forwarded to Temporarily assume that the current directory is a given value, instead of querying it from the environment when needed, in order to improve performance. The current directory to assume. A token representing the registered callback. This should be disposed of when the assumption is no longer required. The usual usage pattern is to capture the token with a using statement, such that it is automatically disposed of when the using block exits. NPath-related extension methods for other common types. Copy these NPaths into the given directory. An enumerable sequence of NPaths. The path to the target directory. The paths to the newly copied files. All path information in the source paths is ignored, other than the final file name; the resulting copied files and directories will all be immediate children of the target directory. Move these NPaths into the given directory. An enumerable sequence of NPaths. The path to the target directory. The paths to the newly moved files. All path information in the source paths is ignored, other than the final file name; the resulting moved files and directories will all be immediate children of the target directory. Delete the files/directories targetted by these paths. The paths to delete. All paths that were passed in to the method. Convert all these paths to quoted strings, using the requested path separator type. The paths to convert. The path separator type to use. Defaults to SlashMode.Forward. The paths, converted to quoted strings. Construct a new NPath from this string. The string to construct the path from. A new NPath constructed from this string. Construct new NPaths from each of these strings. The strings to construct NPaths from. The newly constructed NPaths. Invokes .ResolveWithFileSystem on all NPaths Invokes InQuotesResolved on all NPaths Describes the different kinds of path separators that can be used when converting NPaths back into strings. Use the slash mode that is native for the current platform - backslashes on Windows, forward slashes on macOS and Linux systems. Use forward slashes as path separators. Use backslashes as path separators. Specifies the way that directory deletion should be performed. When deleting a directory, if an IOException occurs, rethrow it. When deleting a directory, if an IOException occurs, ignore it. The deletion request may or may not be later fulfilled by the OS.