Path
Description
- Derived from
-
SerializableBase abstract
IEquatable<Path>
IComparable<Path>
Represents a file path in a file system.
A valid path string is defined by the following Grammar:
path := root? separator? (name (separator name)* separator?)? ; name := ]/\r\\\n[+ ; root := ]/\r\\\n:[+ ':' ; separator := [/\\]+ ;
Not all valid path strings may be accepted by the underlying file system; some characters may be invalid and thus cannot be used (see IOError.BadPath).
Public / Constants
Public / Constructors
From
Parses the given path string and returns the resulting Path object.
- IOException
-
If the given path in is not a valid path name (i.e. FromNull would return
null
).
Guess
Tries to guess a Path value from the given object.
First, the method checks if obj in implements the IPathInfo interface and returns the value of the IPathInfo.PathInfo property in that case. Otherwise a Path value is constructed from the string representation of obj in.
Public / Methods
AppendName
Appends the given path element to this path.
Example:
c:\some\directory\structure or c:\some\directory\structure\ AppendName("myfile.txt") => c:\some\directory\structure\myfile.txt
AppendPath
2 overloads
Appends the given path to this one.
Example:
c:\some\directory\structure or c:\some\directory\structure\ AppendPath("myfile.txt") => c:\some\directory\structure\myfile.txt AppendPath("mydir/myfile.txt") => c:\some\directory\structure\mydir\myfile.txt AppendPath("\myfile.txt") => c:\some\directory\structure\myfile.txt AppendPath("c:myfile.txt") => c:\some\directory\structure\myfile.txt AppendPath("c:\myfile.txt") => c:\some\directory\structure\myfile.txt
- IOException
-
If the given path in is not a valid path name (i.e. FromNull would return
null
).
Appends the given path to this one.
Example:
c:\some\directory\structure or c:\some\directory\structure\ AppendPath("myfile.txt") => c:\some\directory\structure\myfile.txt AppendPath("mydir/myfile.txt") => c:\some\directory\structure\mydir\myfile.txt AppendPath("\myfile.txt") => c:\some\directory\structure\myfile.txt AppendPath("c:myfile.txt") => c:\some\directory\structure\myfile.txt AppendPath("c:\myfile.txt") => c:\some\directory\structure\myfile.txt
AppendSuffix
2 overloads
Appends the given suffix to this path.
Example:
c:\some\directory\structure c:\some\directory\structure\ AppendSuffix(".test") => c:\some\directory\structure.test c:\some\directory\structure\myfile.txt AppendSuffix(".bak") => c:\some\directory\structure\myfile.txt.bak c:\ AppendSuffix("") => c:\ AppendSuffix(".test") => c:\.test
- See also
Appends the given suffix to the last path element of this path.
Example:
c:\some\directory\structure c:\some\directory\structure\ AppendSuffix('.', "test") => c:\some\directory\structure.test c:\some\directory\structure\myfile.txt AppendSuffix('.', "bak") => c:\some\directory\structure\myfile.txt.bak c:\ AppendSuffix('.', "test") => c:\.test
- See also
DeleteAll
Deletes all files resp. directories denoted by toDelete in.
- IOException
-
If an I/O error has occurred.
Matches
Checks if the given wildcard pattern matches the given path value.
Checks if this wildcard Path matches the given path value.
Checks if this wildcard Path matches the given path value.
RemoveLast
Removes the last element from this path.
Example:
c:\some\directory\structure\myfile.txt RemoveLast => c:\some\directory\structure c:\some\directory\structure\ RemoveLast => c:\some\directory c:\some RemoveLast => c:\ c:\ RemoveLast => null
- See also
RemoveSuffix
2 overloads
Removes a suffix from the last named element of this path.
c:\directory\myfile.txt RemoveSuffix('.') => c:\directory\myfile RemoveSuffix('-') => c:\directory\myfile.txt c:\directory\myfile.txt.bak RemoveSuffix('.') => c:\directory\myfile.txt c:\directory.tmp\ RemoveSuffix('.') => c:\directory
- See also
Removes the suffix from the last named element of this path.
Example:
c:\directory\myfile.txt RemoveSuffix(4) => c:\directory\myfile c:\directory\myfile.txt RemoveSuffix(10) => c:\directory RemoveSuffix(11) => c:\directory RemoveSuffix(12) => c:\directory etc. c:\directory\ RemoveSuffix(1) => c:\director
- See also
Resolve
Resolves this path, if it is relative, using the given current in path as the base directory.
If the given current path is null
or Unknown, the method returns this
. If this path is absolute or unknown, the method also returns this
. Otherwise, the method appends this path to the current path.
ToRootSelector
2 overloads
Changes the root selector of this path to null
(i.e. none).
- See also
Changes the root selector of this path.
If the given root in selector does not start with '//'
resp. '\\'
and does not end with ':'
, the root selector format of this path value will be retained.
- See also
Validate
Checks if this path contains only valid characters.
This method checks for additional restrictions on path names that are imposed by the IFileSystem that is associated with this path (see FileSystem.From).
- See also
Public / Attributes
Canonical
Returns the canonical name of this path (i.e. the fully resolved absolute path).
The resolved path will have the following properties:
-
It is absolute (see IsAbsolute).
-
It does not have a trailing directory separator (see IsTrailing).
-
It does not contain any
'.'
elements. -
It does not contain any
'..'
elements. -
All directory separator characters match the one defined by the operating system.
First
Returns the first named element of this path.
Example:
c:\some\directory\structure\myfile.txt First => "some" c:\some\directory\structure\ First => "some" c:\ First => ""
HasRootSelector
Is this path rooted?
On some platforms, a path may contain a root selector (e.g. C:
on windows platforms).
- See also
Home
Returns the canonical path to the current users home directory.
- IOException
-
If an I/O error has occurred while obtaining the home path of the current user.
IsAbsolute
Is this path absolute?
An absolute path points to a file or directory independently of the current directory of the process.
- See also
IsRelative
Is this path relative?
The file or directory a relative path points to is dependent on the current directory of the process.
- See also
IsWildcard
Is this a wildcard path?
The following wildcards are recognized:
-
'*'
: Matches zero or more characters of aname
element. -
'?'
: Matches one character of aname
element.
Last
Returns the last named element of this path.
Example:
c:\some\directory\structure\myfile.txt Last => "myfile.txt" c:\some\directory\structure\ Last => "structure" c:\ Last => ""
- See also
RootSelector
Returns the root selector of this path.
On some platforms, a path may contain a root selector (e.g. C:
on windows platforms):
c:\somefile.txt C:\somefile.txt RootSelector => "c:" /usr/tmp RootSelector => null http://some.website.net RootSelector => "http:"
The root selector contains lower-case characters only.
Extensions
Copy
Copies this file to the given target path.
For copying very large files, Operation.Copy may be used.
- IOException
-
If an I/O error has occurred.
CopyAll
Copies files from this directory to the given directory.
This method uses FindAll and Operation.Copy to build the returned IOperation.
- IOException
-
If an I/O error has occurred.
- See also
Delete
Deletes the file or directory denoted by this path.
This method swallows IOError.NotEmpty errors and returns false
in this case.
- IOException
-
If an I/O error has occurred.
DeleteAll
Recursively deletes all files and directories, starting at this path.
- IOException
-
If an I/O error has occurred.
DirectoryCreate
Creates the directory this path points to.
If the given directory already exists, the method returns silently. The method will create all ancestor directories if necessary.
- IOException
-
If an I/O error has occurred.
DirectoryDelete
Deletes the directory this path points to.
A directory can only be deleted if it is empty. Otherwise, an IOException with IOError.NotEmpty is thrown.
- IOException
-
If an I/O error has occurred.
DirectoryExists
Checks if this path points to an existing directory.
- IOException
-
If an I/O error has occurred.
DirectoryFreeSpace
Returns the amount of storage space that is available in this directory.
If the given directory does not exist, the storage space for the nearest existing ancestor directory is reported. The returned value is intended to be used for coarse-grained resource decisions.
- IOException
-
If an I/O error has occurred.
FileExists
Checks if this path points to an existing file.
- IOException
-
If an I/O error has occurred.
FindAll
Finds all subdirectories and files in the directory pointed to by this Path object which match the given filter.
The found files and directories are added to the resulting collection in such order so that all of them may be deleted by iterating over the collection in reverse order.
- IOException
-
If an I/O error has occurred.
Finder
Returns a PathFinder object that can later be used to find individual files or directories in this directory.
FindSiblingInAncestor
Tries to find a file or directory in the ancestor chain of this directory.
Beginning at the directory pointed to by this Path object, this method probes each parent directory in order to find a file or sub-directory named sibling in.
- IOException
-
If an I/O error has occurred.
ListDirectories
Lists all subdirectories in the given directory.
- IOException
-
If an I/O error has occurred.
MakeCurrent
Makes this path the current directory in its attached filesystem.
- IOException
-
If an I/O error has occurred.
MakeRelative
Tries to create a relative path that points from home in to this path.
The canonical form of this path and home in will be used by this method (see Path.Canonical).
ParentDirectoryCreate
Creates the parent directory.
If the parent directory already exists, the method returns silently.
The method will create all ancestor directories if necessary.
- IOException
-
If an I/O error has occurred.
Rename
Renames this file or directory to the given name in.
- IOException
-
If an I/O error has occurred.
StreamNew
Creates a new instance of IDataStream for this path.
- IOException
-
If an I/O error has occurred.
ThrowIfUnknown
Throws an IOException with IOError.BadPath if this path is unknown.
- IOException
-
If this path is unknown.
- See also
Timestamp
2 overloads
Returns the timestamp of the last file modification.
- IOException
-
If an I/O error has occurred.
- See also
Sets the timestamp of the last file modification.
- IOException
-
If an I/O error has occurred.
- See also
WriteAllBytes
Writes the given bytes to the file pointed to by this path.
- IOException
-
If an I/O error has occurred.
WriteAllText
Writes the given text to the file pointed to by this path.
- IOException
-
If an I/O error has occurred.