mscorlib(4.0.0.0) API with additions
System.IO.Path Class Reference

Performs operations on T:System.String instances that contain file or directory path information. These operations are performed in a cross-platform manner.To browse the .NET Framework source code for this type, see the Reference Source. More...

Static Public Member Functions

static string ChangeExtension (string path, string extension)
 Changes the extension of a path string. More...
 
static string GetDirectoryName (string path)
 Returns the directory information for the specified path string. More...
 
static char [] GetInvalidPathChars ()
 Gets an array containing the characters that are not allowed in path names. More...
 
static char [] GetInvalidFileNameChars ()
 Gets an array containing the characters that are not allowed in file names. More...
 
static string GetExtension (string path)
 Returns the extension of the specified path string. More...
 
static string GetFullPath (string path)
 Returns the absolute path for the specified path string. More...
 
static string GetFileName (string path)
 Returns the file name and extension of the specified path string. More...
 
static string GetFileNameWithoutExtension (string path)
 Returns the file name of the specified path string without the extension. More...
 
static string GetPathRoot (string path)
 Gets the root directory information of the specified path. More...
 
static string GetTempPath ()
 Returns the path of the current user's temporary folder. More...
 
static string GetRandomFileName ()
 Returns a random folder name or file name. More...
 
static string GetTempFileName ()
 Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file. More...
 
static bool HasExtension (string path)
 Determines whether a path includes a file name extension. More...
 
static bool IsPathRooted (string path)
 Gets a value indicating whether the specified path string contains a root. More...
 
static string Combine (string path1, string path2)
 Combines two strings into a path. More...
 
static string Combine (string path1, string path2, string path3)
 Combines three strings into a path. More...
 
static string Combine (string path1, string path2, string path3, string path4)
 Combines four strings into a path. More...
 
static string Combine (params string[] paths)
 Combines an array of strings into a path. More...
 

Static Public Attributes

static readonly char DirectorySeparatorChar = '\\'
 Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization. More...
 
static readonly char AltDirectorySeparatorChar = '/'
 Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization. More...
 
static readonly char VolumeSeparatorChar = ':'
 Provides a platform-specific volume separator character. More...
 
static readonly char [] InvalidPathChars
 Provides a platform-specific array of characters that cannot be specified in path string arguments passed to members of the T:System.IO.Path class. More...
 
static readonly char PathSeparator = ';'
 A platform-specific separator character used to separate path strings in environment variables. More...
 

Detailed Description

Performs operations on T:System.String instances that contain file or directory path information. These operations are performed in a cross-platform manner.To browse the .NET Framework source code for this type, see the Reference Source.

Definition at line 13 of file Path.cs.

Member Function Documentation

◆ ChangeExtension()

static string System.IO.Path.ChangeExtension ( string  path,
string  extension 
)
static

Changes the extension of a path string.

Parameters
pathThe path information to modify. The path cannot contain any of the characters defined in M:System.IO.Path.GetInvalidPathChars.
extensionThe new extension (with or without a leading period). Specify null to remove an existing extension from path .
Returns
The modified path information.On Windows-based desktop platforms, if path is null or an empty string (""), the path information is returned unmodified. If extension is null, the returned string contains the specified path with its extension removed. If path has no extension, and extension is not null, the returned path string contains extension appended to the end of path .
Exceptions
T:System.ArgumentExceptionpath contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.

Definition at line 228 of file Path.cs.

◆ Combine() [1/4]

static string System.IO.Path.Combine ( string  path1,
string  path2 
)
static

Combines two strings into a path.

Parameters
path1The first path to combine.
path2The second path to combine.
Returns
The combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2 .
Exceptions
T:System.ArgumentExceptionpath1 or path2 contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.
T:System.ArgumentNullExceptionpath1 or path2 is null.

Definition at line 1107 of file Path.cs.

◆ Combine() [2/4]

static string System.IO.Path.Combine ( string  path1,
string  path2,
string  path3 
)
static

Combines three strings into a path.

Parameters
path1The first path to combine.
path2The second path to combine.
path3The third path to combine.
Returns
The combined paths.
Exceptions
T:System.ArgumentExceptionpath1 , path2 , or path3 contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.
T:System.ArgumentNullExceptionpath1 , path2 , or path3 is null.

Definition at line 1128 of file Path.cs.

◆ Combine() [3/4]

static string System.IO.Path.Combine ( string  path1,
string  path2,
string  path3,
string  path4 
)
static

Combines four strings into a path.

Parameters
path1The first path to combine.
path2The second path to combine.
path3The third path to combine.
path4The fourth path to combine.
Returns
The combined paths.
Exceptions
T:System.ArgumentExceptionpath1 , path2 , path3 , or path4 contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.
T:System.ArgumentNullExceptionpath1 , path2 , path3 , or path4 is null.

Definition at line 1150 of file Path.cs.

◆ Combine() [4/4]

static string System.IO.Path.Combine ( params string []  paths)
static

Combines an array of strings into a path.

Parameters
pathsAn array of parts of the path.
Returns
The combined paths.
Exceptions
T:System.ArgumentExceptionOne of the strings in the array contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.
T:System.ArgumentNullExceptionOne of the strings in the array is null.

Definition at line 1169 of file Path.cs.

◆ GetDirectoryName()

static string System.IO.Path.GetDirectoryName ( string  path)
static

Returns the directory information for the specified path string.

Parameters
pathThe path of a file or directory.
Returns
Directory information for path , or null if path denotes a root directory or is null. Returns F:System.String.Empty if path does not contain directory information.
Exceptions
T:System.ArgumentExceptionThe path parameter contains invalid characters, is empty, or contains only white spaces.
T:System.IO.PathTooLongExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, T:System.IO.IOException, instead.The path parameter is longer than the system-defined maximum length.

Definition at line 268 of file Path.cs.

◆ GetExtension()

static string System.IO.Path.GetExtension ( string  path)
static

Returns the extension of the specified path string.

Parameters
pathThe path string from which to get the extension.
Returns
The extension of the specified path (including the period "."), or null, or F:System.String.Empty. If path is null, M:System.IO.Path.GetExtension(System.String) returns null. If path does not have extension information, M:System.IO.Path.GetExtension(System.String) returns F:System.String.Empty.
Exceptions
T:System.ArgumentExceptionpath contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.

Definition at line 405 of file Path.cs.

◆ GetFileName()

static string System.IO.Path.GetFileName ( string  path)
static

Returns the file name and extension of the specified path string.

Parameters
pathThe path string from which to obtain the file name and extension.
Returns
The characters after the last directory character in path . If the last character of path is a directory or volume separator character, this method returns F:System.String.Empty. If path is null, this method returns null.
Exceptions
T:System.ArgumentExceptionpath contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.

Definition at line 914 of file Path.cs.

◆ GetFileNameWithoutExtension()

static string System.IO.Path.GetFileNameWithoutExtension ( string  path)
static

Returns the file name of the specified path string without the extension.

Parameters
pathThe path of the file.
Returns
The string returned by M:System.IO.Path.GetFileName(System.String), minus the last period (.) and all characters following it.
Exceptions
T:System.ArgumentExceptionpath contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.

Definition at line 939 of file Path.cs.

◆ GetFullPath()

static string System.IO.Path.GetFullPath ( string  path)
static

Returns the absolute path for the specified path string.

Parameters
pathThe file or directory for which to obtain absolute path information.
Returns
The fully qualified location of path , such as "C:\MyFile.txt".
Exceptions
T:System.ArgumentExceptionpath is a zero-length string, contains only white space, or contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.-or- The system could not retrieve the absolute path.
T:System.Security.SecurityExceptionThe caller does not have the required permissions.
T:System.ArgumentNullExceptionpath is null.
T:System.NotSupportedExceptionpath contains a colon (":") that is not part of a volume identifier (for example, "c:\").
T:System.IO.PathTooLongExceptionThe specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

Definition at line 446 of file Path.cs.

◆ GetInvalidFileNameChars()

static char [] System.IO.Path.GetInvalidFileNameChars ( )
static

Gets an array containing the characters that are not allowed in file names.

Returns
An array containing the characters that are not allowed in file names.

Definition at line 394 of file Path.cs.

◆ GetInvalidPathChars()

static char [] System.IO.Path.GetInvalidPathChars ( )
static

Gets an array containing the characters that are not allowed in path names.

Returns
An array containing the characters that are not allowed in path names.

Definition at line 386 of file Path.cs.

◆ GetPathRoot()

static string System.IO.Path.GetPathRoot ( string  path)
static

Gets the root directory information of the specified path.

Parameters
pathThe path from which to obtain root directory information.
Returns
The root directory of path , such as "C:\", or null if path is null, or an empty string if path does not contain root directory information.
Exceptions
T:System.ArgumentExceptionpath contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.-or- F:System.String.Empty was passed to path .

Definition at line 961 of file Path.cs.

◆ GetRandomFileName()

static string System.IO.Path.GetRandomFileName ( )
static

Returns a random folder name or file name.

Returns
A random folder name or file name.

Definition at line 997 of file Path.cs.

◆ GetTempFileName()

static string System.IO.Path.GetTempFileName ( )
static

Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.

Returns
The full path of the temporary file.
Exceptions
T:System.IO.IOExceptionAn I/O error occurs, such as no unique temporary file name is available.- or -This method was unable to create a temporary file.

Definition at line 1020 of file Path.cs.

◆ GetTempPath()

static string System.IO.Path.GetTempPath ( )
static

Returns the path of the current user's temporary folder.

Returns
The path to the temporary folder, ending with a backslash.
Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permissions.

Definition at line 976 of file Path.cs.

◆ HasExtension()

static bool System.IO.Path.HasExtension ( string  path)
static

Determines whether a path includes a file name extension.

Parameters
pathThe path to search for an extension.
Returns
true if the characters that follow the last directory separator (\ or /) or volume separator (:) in the path include a period (.) followed by one or more characters; otherwise, false.
Exceptions
T:System.ArgumentExceptionpath contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.

Definition at line 1051 of file Path.cs.

◆ IsPathRooted()

static bool System.IO.Path.IsPathRooted ( string  path)
static

Gets a value indicating whether the specified path string contains a root.

Parameters
pathThe path to test.
Returns
true if path contains a root; otherwise, false.
Exceptions
T:System.ArgumentExceptionpath contains one or more of the invalid characters defined in M:System.IO.Path.GetInvalidPathChars.

Definition at line 1084 of file Path.cs.

Member Data Documentation

◆ AltDirectorySeparatorChar

readonly char System.IO.Path.AltDirectorySeparatorChar = '/'
static

Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.

Definition at line 23 of file Path.cs.

◆ DirectorySeparatorChar

readonly char System.IO.Path.DirectorySeparatorChar = '\\'
static

Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.

Definition at line 17 of file Path.cs.

◆ InvalidPathChars

readonly char [] System.IO.Path.InvalidPathChars
static

Provides a platform-specific array of characters that cannot be specified in path string arguments passed to members of the T:System.IO.Path class.

Returns
A character array of invalid path characters for the current platform.

Definition at line 32 of file Path.cs.

◆ PathSeparator

readonly char System.IO.Path.PathSeparator = ';'
static

A platform-specific separator character used to separate path strings in environment variables.

Definition at line 165 of file Path.cs.

◆ VolumeSeparatorChar

readonly char System.IO.Path.VolumeSeparatorChar = ':'
static

Provides a platform-specific volume separator character.

Definition at line 27 of file Path.cs.


The documentation for this class was generated from the following file: