Mono.Unix.UnixPath Class
Performs operations on string instances that contain file or directory path information.

See Also: UnixPath Members

Syntax

public sealed class UnixPath

Remarks

A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk; for example, a path may map to a location in memory or on a device. Paths are composed of the components described below. Component names are shown in italics and the following table describes the symbols used in component definitions:

SymbolDescription
< >Indicates a path component.
{ } Indicates a grouping; either all components in a grouping are present, or none are permitted to be present.
* Indicates that the component or grouping that immediately precedes this symbol can appear zero, one, or multiple times.
? Indicates that the component or grouping that immediately precedes this symbol can appear zero, or one times.
+Indicates string concatenation.

The components that define a path are as follows:

Directory Name: A string that specifies one or more directory levels in a file system. If a directory name contains multiple levels, a directory separator character separates the levels; however, a directory name does not begin or end with a directory separator character. In the example path /foo/bar/bat.txt, the directory name is "foo/bar". UnixPath.GetDirectoryName(string) returns the directory name component of a path. Note that this method does include a beginning separator character if one is included in the specified path.

Directory Separator Character: An implementation-defined constant string containing a single printable non-alphanumeric character used to separate levels in a file system. In the example path /foo/bar/bat.txt, the directory separator character is "/". The UnixPath.DirectorySeparatorChar and UnixPath.AltDirectorySeparatorChar store implementation-defined directory separator characters.

Extension: A string that consists of the characters at the end of a file name, from and including the last extension separator character. The minimum and maximum lengths of extension components are platform-specific. In the example path "/foo/bar/bat.txt", the extension is ".txt". The System.IO.Path.GetExtension(string) method returns the extension component of a path.

Extension Separator Character: An implementation-defined constant string composed of a single character that appears after the last character in the file base component indicating the beginning of the extension component. If the extension separator character "." is the first character in a file name, it is not interpreted as a extension separator character. If more than one extension separator character appears in a file name, only the last occurrence is the extension separator character; all other occurrences are part of the file base component. In the example path "/foo/bar/bat.txt", the extension separator character is ".".

File Base: A string containing the file name with the extension component removed. In the example path "/foo/bar/bat.txt", the file base is "bat". The System.IO.Path.GetFileNameWithoutExtension(string) method returns the file base component of a path.

File Name: A string containing all information required to uniquely identify a file within a directory. This component is defined as follows:

<file base>{+<extension>}?

The file name component is commonly referred to as a relative file name. In the example path "/foo/bar/bat.txt", the file name is "bat.txt". The UnixPath.GetFileName(string) method returns the file name component of a path.

Full Directory Name: A string containing all information required to uniquely identify a directory within a file system. This component is defined as follows:

<path root>+<directory name>

The full directory name component is commonly referred to as the absolute directory name. In the example path "/foo/bar/bat.txt", the full directory name is "/foo/bar".

Full Path: A string containing all information required to uniquely identify a file within a file system. This component is defined as follows:

<full directory name>+<directory separator character>+<file name>

The full path component is commonly referred to as the absolute file name. In the example path "/foo/bar/bat.txt", the full path is "/foo/bar/bat.txt". The UnixPath.GetFullPath(string) method returns the full path component.

Path Root: A string containing all information required to uniquely identify the highest level in a file system. The component is defined as follows:

{<volume identifier>+<volume separator character>}?+<directory separator character>

In the example path /foo/bar/bat.txt , the path root is "/". The UnixPath.GetPathRoot(string) method returns the path root component.

The exact format of a path is determined by the current platform. On some systems, paths containing file names can contain extensions. The format of an extension is platform dependent; for example, some systems limit extensions to three characters, while others do not. The current platform and possibly the current file system determine the set of characters used to separate the elements of a path, and the set of characters that cannot be used when specifying paths. Because of these differences, the fields of the Mono.Unix.UnixPath class as well as the exact behavior of some members of the Mono.Unix.UnixPath class are determined by the current platform and/or file system.

A path contains either absolute or relative location information. Absolute paths fully specify a location: the file or directory can be uniquely identified regardless of the current location. A full path or full directory name component is present in an absolute path. Relative paths specify a partial location: the current working directory is used as the starting point when locating a file specified with a relative path.

Note: To determine the current working directory, call UnixDirectoryInfo.GetCurrentDirectory.

Most members of the UnixPath class do not interact with the file system and do not verify the existence of the file or directory specified by a path string. Mono.Unix.UnixPath members that modify a path string, such as UnixPath.Combine(string, string), have no effect on files and directories in the file system. Mono.Unix.UnixPath members do, however, validate the contents of a specified path string, and throw ArgumentException if the string contains characters that are not valid in path strings, as defined by the current platform and file system. Implementations are required to preserve the case of file and directory path strings, and to be case sensitive if and only if the current platform is case-sensitive.

Thread Safety

This type is safe for multithreaded operations.

Requirements

Namespace: Mono.Unix
Assembly: Mono.Posix (in Mono.Posix.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0