Represents a file path in a file system.
sealed class
|
Path
|
implements
|
IComparable<Path>
|
||
IEquatable<Path>
|
|||||
extends
|
SerializableBase
|
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 BadPath).
Serialization information about this type.
public
static
readonly
field
|
SerialId
|
||
type
|
ISerialTypeInfo
|
A
relative
Path
object
for
the
current
directory:
'.'
public
static
readonly
field
|
Current
|
||
type
|
Path
|
A
relative
Path
object
for
the
parent
directory:
'.'
public
static
readonly
field
|
Parent
|
||
type
|
Path
|
An
absolute
Path
object
for
the
root
directory:
'/'
.
public
static
readonly
field
|
Root
|
||
type
|
Path
|
Special Path object for representing an unknown file path.
public
static
readonly
field
|
Unknown
|
||
type
|
Path
|
Returns the canonical name of the given path (i.e. the fully resolved absolute path).
public
property
|
Canonical
{
get
}
|
||
type
|
Path
|
||
value
|
|
The canonical path. |
Remarks:
The resolved path will have the following properties:
'.'
elements.'..'
elements.Returns the first named element of this path.
public
property
|
First
{
get
}
|
||
type
|
string
|
||
value
|
The last path part. |
Remarks:
Example:
c:\some\directory\structure\myfile.txt First => "some" c:\some\directory\structure\ First => "some" c:\ First => ""
Returns
the
grammar
rule
('path'
)
for
parsing
a
path
value.
public
static
property
|
GrammarRulePath
{
get
}
|
||
type
|
IGrammarRule
|
||
value
|
|
The grammar rule. |
Is this path rooted?
public
property
|
HasRootSelector
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
path
has
a
root
selector,
false
if
it
does
not. |
Remarks:
On
some
platforms,
a
path
may
contain
a
root
selector
(e.g.
C:
on
windows
platforms).
See also:
RootSelectorReturns the full path to the current users home directory.
public
static
property
|
Home
{
get
}
|
||
type
|
Path
|
||
value
|
|
The home path. |
Is this path absolute?
public
property
|
IsAbsolute
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
path
is
absolute,
false
if
it
is
relative. |
Remarks:
An absolute path points to a file or directory independently of the current directory of the process.
See also:
ToAbsoluteIs this path in canonical form?
public
property
|
IsCanonical
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
path
is
in
canonical
form,
false
if
not. |
See also:
CanonicalIs this path relative?
public
property
|
IsRelative
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
path
is
relative,
false
if
it
is
absolute. |
Remarks:
The file or directory a relative path points to is dependent on the current directory of the process.
See also:
ToRelativeDoes this path string end with a directory separator?
public
property
|
IsTrailing
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
the
path
ends
with
a
separator,
false
if
not. |
See also:
ToTrailingIs this an unknown path?
public
property
|
IsUnknown
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
is
an
unknown
path,
false
if
not. |
Is this a wildcard path?
public
property
|
IsWildcard
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
path
contains
one
or
more
wildcards,
false
it
not.
|
Remarks:
The following wildcards are recognized:
'*'
:
Matches
zero
or
more
characters
of
a
name
element.'?'
:
Matches
one
character
of
a
name
element.Returns the last named element of this path.
public
property
|
Last
{
get
}
|
||
type
|
string
|
||
value
|
The last path part. |
Remarks:
Example:
c:\some\directory\structure\myfile.txt Last => "myfile.txt" c:\some\directory\structure\ Last => "structure" c:\ Last => ""
See also:
RemoveLastReturns the number of characters in this path string.
public
property
|
Length
{
get
}
|
||
type
|
int32
|
||
value
|
|
The number of characters in the path string |
Returns the root selector of this path.
public
property
|
RootSelector
{
get
}
|
||
type
|
string
|
||
value
|
The
root
selector
or
null
if
this
path
does
not
have
one. |
Remarks:
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.
See also:
HasRootSelectorReturns the length of the root selector of this path.
public
property
|
RootSelectorLength
{
get
}
|
||
type
|
int32
|
||
value
|
|
The root selector length. |
Returns the serial type of this object.
public
property
|
SerialType
{
get
}
|
||
type
|
ISerialTypeInfo
|
||
value
|
|
The serial type. | |
inherited
|
SerializableBase.SerialType
|
Returns the serial data version.
public
virtual
property
|
SerialVersion
{
get
}
|
||
type
|
int32
|
||
value
|
|
The serial data version tag. | |
inherited
|
SerializableBase.SerialVersion
|
Remarks:
An ISerializable implementation is required to support all versions up to the one returned by SerialVersion.
See also:
ISerializable.SerializeReturns the full path to the systems temp directory.
public
static
property
|
Temp
{
get
}
|
||
type
|
Path
|
||
value
|
|
The temp path. |
Returns the first non-null path.
[Pure]
|
||||
public
static
method
|
Coalesce
(IPathInfo a)
|
|||
type
|
Path
|
|||
params
|
a
|
First path value. | ||
returns
|
|
The first non-null path or Unknown. |
Parses the given path string and returns the resulting Path object.
[Pure]
|
||||
public
static
method
|
From
(string path)
|
|||
type
|
Path
|
|||
params
|
path
|
[not-empty]
|
The path string. | |
returns
|
|
The Path object. |
Exceptions:
Parses the given path string and returns the resulting Path object.
[Pure]
|
||||
public
static
method
|
FromNull
(string path)
|
|||
type
|
Path
|
|||
params
|
path
|
The path string. | ||
returns
|
The
Path
object
or
null
if
the
given
path
string
is
invalid.
|
Tries to guess a Path value from the given object.
public
static
method
|
Guess
(object obj)
|
||
type
|
Path
|
||
params
|
obj
|
Some object reference. | |
returns
|
|
The guessed Path value or Unknown. |
Remarks:
First, the method checks if obj implements the IPathInfo interface and returns the value of the PathInfo property in that case. Otherwise a Path value is constructed from the string representation of obj.
Appends the given path element to this path.
[Pure]
|
||||
public
method
|
AppendName
(string name)
|
|||
type
|
Path
|
|||
params
|
name
|
[not-empty]
|
The path element to add. | |
returns
|
|
The resulting path. |
Remarks:
Example:
c:\some\directory\structure or c:\some\directory\structure\ Append("myfile.txt") => c:\some\directory\structure\myfile.txt
Appends the given path to this one.
[Pure]
|
||||
public
method
|
AppendPath
(Path path)
|
|||
type
|
Path
|
|||
params
|
path
|
[not-null]
|
The other path. | |
returns
|
|
The resulting path. |
Remarks:
Example:
c:\some\directory\structure or c:\some\directory\structure\ Append("myfile.txt") => c:\some\directory\structure\myfile.txt Append("mydir/myfile.txt") => c:\some\directory\structure\mydir\myfile.txt Append("\myfile.txt") => c:\some\directory\structure\myfile.txt Append("c:myfile.txt") => c:\some\directory\structure\myfile.txt Append("c:\myfile.txt") => c:\some\directory\structure\myfile.txt
Appends the given suffix to this path.
[Pure]
|
||||
public
method
|
AppendSuffix
(string suffix)
|
|||
type
|
Path
|
|||
params
|
suffix
|
[not-empty]
|
The suffix to append. | |
returns
|
|
The resulting path. |
Remarks:
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:
HasSuffixAppends the given suffix to the last path element of this path.
[Pure]
|
||||
public
method
|
AppendSuffix
(char delimiter,
string suffix)
|
|||
type
|
Path
|
|||
params
|
delimiter
|
The delimiter char to append. | ||
suffix
|
[not-empty]
|
The suffix to append. | ||
returns
|
|
The resulting path. |
Remarks:
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:
GetSuffixReturns the first non-null path.
[Pure]
|
||||
public
static
method
|
Coalesce
(Path a,
Path b = null)
|
|||
type
|
Path
|
|||
params
|
a
|
First
path
value
(can
be
null ). |
||
b
|
Second
path
value
(can
be
null ). |
|||
returns
|
|
The first non-null path or Unknown. |
Compares this object with the given one.
[Pure]
|
||||
public
method
|
CompareTo
(Path other)
|
|||
type
|
int32
|
|||
params
|
other
|
The object to compare to. | ||
returns
|
<
0
:
if
this
object
is
less
than
other, = 0 : if this object is equal to other, > 0 : if this object is greater than other. |
|||
implements
|
IComparable.CompareTo
|
Concatenates the given path values.
[Pure]
|
||||
public
static
method
|
Concat
(Path a,
Path b)
|
|||
type
|
Path
|
|||
params
|
a
|
First
path
value
or
null . |
||
b
|
Second
path
value
or
null . |
|||
returns
|
The resulting path value. |
Initializes the state of this object from the given data stream.
public
override
method
|
Deserialize
(int32 serialVersion,
ISerializer data)
|
||
type
|
ISerializable
|
||
params
|
serialVersion
|
[>=1]
|
The serial data version. |
data
|
[not-null]
|
The serial data stream. | |
returns
|
|
The
deserialized
object.
This
will
typically
be
this ,
but
in
some
circumstances,
another
instance
may
be
returned
(e.g.
singletons).
|
|
overrides
|
SerializableBase.Deserialize
|
Remarks:
The Deserialize method will be called immediately after the object has been instantiated via its default constructor.
The provided serialVersion number is guaranteed to be equal to or less than the SerialVersion returned by this object (i.e. ISerializable object must provide backwards compatibility).
See also:
ISerializable.SerializeCompares this object with the given one.
[Pure]
|
||||
public
override
method
|
Equals
(object other)
|
|||
type
|
bool
|
|||
params
|
other
|
The object to compare to. | ||
returns
|
true
if
this
object
is
equal
to
other,
false
if
not.
|
Compares this object with the given one.
[Pure]
|
||||
public
method
|
Equals
(Path other)
|
|||
type
|
bool
|
|||
params
|
other
|
The object to compare to. | ||
returns
|
true
if
this
object
is
equal
to
other,
false
if
not.
|
|||
implements
|
IEquatable.Equals
|
Returns the IFileSystem object that owns this path value.
[Pure]
|
||||
public
method
|
GetFileSystem
()
|
|||
type
|
IFileSystem
|
|||
returns
|
|
The IFileSystem to use. |
[Pure]
|
||||
public
override
method
|
GetHashCode
()
|
|||
type
|
int32
|
Returns the suffix of the last named element of this path.
[Pure]
|
||||
public
method
|
GetSuffix
(char delimiter = ''.'')
|
|||
type
|
string
|
|||
params
|
delimiter
|
The
suffix
delimiter
character.
Defaults
to
'.' . |
||
returns
|
The suffix string (excluding the delimiter character); will be an empty string if this path does not include a suffix. |
See also:
AppendSuffixChecks if the last named element of this path ends with the given suffix.
[Pure]
|
||||
public
method
|
HasSuffix
(string suffix)
|
|||
type
|
bool
|
|||
params
|
suffix
|
[not-null]
|
The name suffix. | |
returns
|
true
if
this
path
ends
in
suffix,
false
if
not.
|
See also:
AppendSuffixIs the given string a valid name for a single path element (i.e. file or directory name)?
[Pure]
|
||||
public
static
method
|
IsName
(string name)
|
|||
type
|
bool
|
|||
params
|
name
|
The name to test. | ||
returns
|
true
if
name
is
a
valid
path
element
name,
false
if
not. |
See also:
FirstChecks if this wildcard Path matches the given path value.
[Pure]
|
||||
public
method
|
Matches
(string other)
|
|||
type
|
bool
|
|||
params
|
other
|
The path value. | ||
returns
|
true
if
other
matches
this
wildcard
path,
false
if
it
does
not.
|
Checks if this wildcard Path matches the given path value.
[Pure]
|
||||
public
method
|
Matches
(Path other)
|
|||
type
|
bool
|
|||
params
|
other
|
The path value. | ||
returns
|
true
if
other
matches
this
wildcard
path,
false
if
it
does
not.
|
Checks if the given wildcard pattern matches the given path value.
[Pure]
|
||||
public
static
method
|
Matches
(string pattern,
string other)
|
|||
type
|
bool
|
|||
params
|
pattern
|
The wildcard pattern. | ||
other
|
The path value. | |||
returns
|
true
if
other
matches
this
wildcard
path,
false
if
it
does
not.
|
Removes the last element from this path.
[Pure]
|
||||
public
method
|
RemoveLast
()
|
|||
type
|
Path
|
|||
returns
|
The
resulting
path
or
null
if
this
path
has
no
elements. |
Remarks:
Example:
c:\some\directory\structure\myfile.txt Parent => c:\some\directory\structure c:\some\directory\structure\ Parent => c:\some\directory c:\some Parent => c:\ c:\ Parent => null
See also:
LastRemoves the given prefix path from this path, if possible.
[Pure]
|
||||
public
method
|
RemovePrefix
(Path prefix,
Path unrelated = null)
|
|||
type
|
Path
|
|||
params
|
prefix
|
The prefix path. | ||
unrelated
|
The
value
to
return
if
this
path
is
unrelated
to
prefix.
Defaults
to
null .
|
|||
returns
|
The resulting path (will be relative to prefix) or unrelated if this path is unrelated to prefix). |
Removes a suffix from the last named element of this path.
[Pure]
|
||||
public
method
|
RemoveSuffix
(char delimiter = ''.'')
|
|||
type
|
Path
|
|||
params
|
delimiter
|
The
suffix
delimiter
character.
Defaults
to
'.' . |
||
returns
|
|
The resulting path. |
Remarks:
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:
AppendSuffixRemoves the suffix from the last named element of this path.
[Pure]
|
||||
public
method
|
RemoveSuffix
(int32 count)
|
|||
type
|
Path
|
|||
params
|
count
|
[>=0]
|
The number of suffix characters to remove. | |
returns
|
|
The resulting path. |
Remarks:
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:
AppendSuffixResolves this path, if it is relative, using the given current path as the base directory.
public
method
|
Resolve
(Path current)
|
||
type
|
Path
|
||
params
|
current
|
The current path. | |
returns
|
|
The resolved path (not necessarily in canonical form). |
Remarks:
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
the
current
path
and
this
path.
Serializes the current state of this object to the given data stream.
public
override
method
|
Serialize
(ISerializer data)
|
||
params
|
data
|
[not-null]
|
The serial data stream. |
overrides
|
SerializableBase.Serialize
|
See also:
ISerializable.DeserializeMakes this path absolute.
[Pure]
|
||||
public
method
|
ToAbsolute
()
|
|||
type
|
Path
|
|||
returns
|
|
The resulting path. |
See also:
IsAbsoluteMakes this path relative.
[Pure]
|
||||
public
method
|
ToRelative
()
|
|||
type
|
Path
|
|||
returns
|
|
The resulting path. |
Changes the root selector of this path.
[Pure]
|
||||
public
method
|
ToRootSelector
(string root)
|
|||
type
|
Path
|
|||
params
|
root
|
The
new
root
selector
or
null . |
||
returns
|
|
The resulting path. |
See also:
RootSelector
[Pure]
|
||||
public
override
method
|
ToString
()
|
|||
type
|
string
|
Appends or removes the trailing directory separator, if necessary.
[Pure]
|
||||
public
method
|
ToTrailing
(bool trailing)
|
|||
type
|
Path
|
|||
params
|
trailing
|
true
to
append
a
trailing
directory
separator,
if
not
present,
false
to
remove
the
trailing
directory
separator,
if
present.
|
||
returns
|
|
The resulting path. |
See also:
IsTrailingReturns this path as a local file URL.
[Pure]
|
||||
public
method
|
ToUrl
()
|
|||
type
|
string
|
|||
returns
|
|
The URL string. |
Creates the given directory.
method
|
DirectoryCreate
()
|
Remarks:
If the given directory already exists, the method returns silently.
The method will create all ancestor directories if necessary.
Deletes the given directory.
method
|
DirectoryDelete
()
|
||
type
|
bool
|
||
returns
|
true
if
the
directory
has
been
deleted,
false
if
it
not. |
Remarks:
A directory can only be deleted if it is empty.
Checks if the given directory exists.
method
|
DirectoryExists
()
|
||
type
|
bool
|
||
returns
|
true
if
the
directory
exists,
false
if
not. |
Returns the amount of storage space that is available in this directory.
method
|
DirectoryFreeSpace
()
|
||
type
|
int64
|
||
returns
|
|
The available storage space, in bytes. |
Remarks:
If the directory does not exist, the storage space for the nearest existing ancestor directory is reported.
Deletes the given file, if it exists.
method
|
FileDelete
()
|
||
type
|
bool
|
||
returns
|
true
if
the
file
has
been
deleted,
false
if
not. |
Shortcut to FileExists.
method
|
FileExists
()
|
||
type
|
bool
|
||
returns
|
true
if
path
points
to
an
existing
file,
false
if
not.
|
Creates a new instance of IFile for this path.
[OwnerReturn]
|
||||
method
|
FileNew
(FileFlags flags)
|
|||
type
|
IFile
|
|||
params
|
flags
|
The file flags (creation disposition and behaviour flags). | ||
returns
|
|
The created file. |
Finds all subdirectories and files in the directory pointed to by this Path object which match the given filter.
method
|
FindAll
(PredicateDelegate<Path> filter = null,
PredicateDelegate<Path> recur = null,
IBag<Path> found = null)
|
||
type
|
IBag<Path>
|
||
params
|
filter
|
The
filter
predicate
that
determines
which
Path
s
to
collect
in
found.
If
null ,
all
child
Path
s
are
collected.
Defaults
to
null .
|
|
recur
|
The
filter
predicate
that
decides
whether
to
recur
into
the
testes
directory
or
not.
If
null ,
recursion
is
done
for
all
child
directories.
Defaults
to
null .
|
||
found
|
Output
collection
for
found
Path
s.
If
null ,
a
new
collection
is
created.
Defaults
to
null .
|
||
returns
|
|
A collection that holds all found Path s. |
Returns a PathFinder object that can later be used to find individual files or directories in this directory.
method
|
Finder
(string pattern = null)
|
||
type
|
PathFinder
|
||
params
|
pattern
|
Optional
name
pattern
using
'?'
and
'*'
wildcards.
If
null ,
the
wildcards
in
this
path
are
used,
if
present
(see
IsWildcard);
otherwise
all
files
or
directories
are
found.
Defaults
to
null .
|
|
returns
|
|
The PathFinder object. |
Tries to find a file or directory in the ancestor chain of this directory.
method
|
FindSiblingInAncestor
(string sibling)
|
||
type
|
Path
|
||
params
|
sibling
|
[not-empty]
|
Name of the file or directory to find. |
returns
|
The
full
path
to
the
found
file
or
directory
or
null
if
no
directory
has
been
found.
|
Remarks:
Beginning at the directory pointed to by this Path object, this method probes each parent directory in order to find a file or subdirectory named sibling.
Lists all subdirectories in the given directory.
method
|
ListDirectories
(string pattern = null)
|
||
type
|
Path[]
|
||
params
|
pattern
|
Optional
name
pattern
using
'?'
and
'*'
wildcards.
Defaults
to
null .
|
|
returns
|
|
The list of canonical directory paths. The returned list order has no particular sort order. |
Lists all files in the given directory.
method
|
ListFiles
(string pattern = null)
|
||
type
|
Path[]
|
||
params
|
pattern
|
Optional
name
pattern
using
'?'
and
'*'
wildcards.
Defaults
to
null .
|
|
returns
|
|
The list of canonical file paths. The returned list order has no particular sort order. |
Makes this path the current directory in its attached filesystem.
method
|
MakeCurrent
()
|
Tries to create a relative path that points from home to this path.
method
|
MakeRelative
(Path home,
bool appendCurrent = false)
|
||
type
|
Path
|
||
params
|
home
|
[not-null]
|
The home path. |
appendCurrent
|
Append
Current
before
returning
a
relative
path
(e.g.
'./my/relative/path'
instead
of
'my/relative/path' )?
Defaults
to
false .
|
||
returns
|
The
relative
path
from
home
to
this
or
null
if
no
relative
path
has
been
found.
|
Remarks:
The canonical form of this path and home will be used by this method (see Canonical).
Creates the parent directory.
method
|
ParentDirectoryCreate
()
|
||
type
|
Path
|
||
returns
|
|
this |
Remarks:
If the parent directory already exists, the method returns silently.
The method will create all ancestor directories if necessary.
Reads all bytes from this file.
[OwnerReturn]
|
||||
method
|
ReadAllBytes
()
|
|||
type
|
ByteBuffer
|
|||
returns
|
|
A buffer holding all bytes. |
Reads all text from this file.
method
|
ReadAllText
(CharacterEncoding encoding = null,
bool bom = false)
|
||
type
|
string
|
||
params
|
encoding
|
The
character
encoding
to
use
(giving
null
will
use
ASCII).
Defaults
to
null .
|
|
bom
|
Consume
a
byte-order
mark
to
choose
the
character
encoding
(will
override
encoding,
if
present)?
Defaults
to
false .
|
||
returns
|
|
The file text. |
Creates a new instance of IDataStream for this path.
[OwnerReturn]
|
||||
method
|
StreamNew
(FileFlags flags,
int32 bufferSize = 65536)
|
|||
type
|
IDataStream
|
|||
params
|
flags
|
The file flags (creation disposition and behaviour flags). | ||
bufferSize
|
[>0]
|
The
buffer
size
to
use.
Defaults
to
65536 . |
||
returns
|
|
The created file stream. |
Writes the given bytes to the file pointed to by this path.
method
|
WriteAllBytes
(ByteBuffer buffer)
|
||
params
|
buffer
|
[not-null]
|
The byte buffer. |
Writes the given text to the file pointed to by this path.
method
|
WriteAllText
(string text,
CharacterEncoding encoding = null,
bool bom = false)
|
||
params
|
text
|
[not-null]
|
The text to write. |
encoding
|
The
character
encoding
to
use
(giving
null
will
use
ASCII).
Defaults
to
null .
|
||
bom
|
Output
a
byte-order
mark
(BOM),
if
applicable
to
the
chosen
encoding?
Defaults
to
false .
|