Path.IsPathRooted Path.IsPathRooted Path.IsPathRooted Path.IsPathRooted Method

定義

オーバーロード

IsPathRooted(ReadOnlySpan<Char>) IsPathRooted(ReadOnlySpan<Char>) IsPathRooted(ReadOnlySpan<Char>) IsPathRooted(ReadOnlySpan<Char>)
IsPathRooted(String) IsPathRooted(String) IsPathRooted(String) IsPathRooted(String)

指定したパス文字列にルートが含まれているかどうかを示す値を取得します。Gets a value indicating whether the specified path string contains a root.

IsPathRooted(ReadOnlySpan<Char>) IsPathRooted(ReadOnlySpan<Char>) IsPathRooted(ReadOnlySpan<Char>) IsPathRooted(ReadOnlySpan<Char>)

public:
 static bool IsPathRooted(ReadOnlySpan<char> path);
public static bool IsPathRooted (ReadOnlySpan<char> path);
static member IsPathRooted : ReadOnlySpan<char> -> bool
Public Shared Function IsPathRooted (path As ReadOnlySpan(Of Char)) As Boolean

パラメーター

戻り値

IsPathRooted(String) IsPathRooted(String) IsPathRooted(String) IsPathRooted(String)

指定したパス文字列にルートが含まれているかどうかを示す値を取得します。Gets a value indicating whether the specified path string contains a root.

public:
 static bool IsPathRooted(System::String ^ path);
public static bool IsPathRooted (string path);
static member IsPathRooted : string -> bool
Public Shared Function IsPathRooted (path As String) As Boolean

パラメーター

path
String String String String

テストするパス。The path to test.

戻り値

path にルートが含まれている場合は true。それ以外の場合は falsetrue if path contains a root; otherwise, false.

例外

path が、GetInvalidPathChars() で定義されている無効な文字を 1 つ以上含んでいます。path contains one or more of the invalid characters defined in GetInvalidPathChars().

コード例を次に示しますが、どのようにIsPathRootedメソッドを使用して、3 つの文字列をテストします。The following code example demonstrates how the IsPathRooted method can be used to test three strings.

String^ fileName = "C:\\mydir\\myfile.ext";
String^ UncPath = "\\\\myPc\\mydir\\myfile";
String^ relativePath = "mydir\\sudir\\";
bool result;
result = Path::IsPathRooted( fileName );
Console::WriteLine( "IsPathRooted('{0}') returns {1}", fileName, result.ToString() );
result = Path::IsPathRooted( UncPath );
Console::WriteLine( "IsPathRooted('{0}') returns {1}", UncPath, result.ToString() );
result = Path::IsPathRooted( relativePath );
Console::WriteLine( "IsPathRooted('{0}') returns {1}", relativePath, result.ToString() );

// This code produces output similar to the following:
//
// IsPathRooted('C:\mydir\myfile.ext') returns True
// IsPathRooted('\\myPc\mydir\myfile') returns True
// IsPathRooted('mydir\sudir\') returns False
string fileName = @"C:\mydir\myfile.ext";
string UncPath = @"\\myPc\mydir\myfile";
string relativePath = @"mydir\sudir\";
bool result;

result = Path.IsPathRooted(fileName);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    fileName, result);

result = Path.IsPathRooted(UncPath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    UncPath, result);

result = Path.IsPathRooted(relativePath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    relativePath, result);

// This code produces output similar to the following:
//
// IsPathRooted('C:\mydir\myfile.ext') returns True
// IsPathRooted('\\myPc\mydir\myfile') returns True
// IsPathRooted('mydir\sudir\') returns False
Dim fileName As String = "C:\mydir\myfile.ext"
Dim UncPath As String = "\\myPc\mydir\myfile"
Dim relativePath As String = "mydir\sudir\"
Dim result As Boolean

result = Path.IsPathRooted(fileName)
Console.WriteLine("IsPathRooted('{0}') returns {1}", fileName, result)

result = Path.IsPathRooted(UncPath)
Console.WriteLine("IsPathRooted('{0}') returns {1}", UncPath, result)

result = Path.IsPathRooted(relativePath)
Console.WriteLine("IsPathRooted('{0}') returns {1}", relativePath, result)

' This code produces output similar to the following:
'
' IsPathRooted('C:\mydir\myfile.ext') returns True
' IsPathRooted('\\myPc\mydir\myfile') returns True
' IsPathRooted('mydir\sudir\') returns False

注釈

IsPathRootedメソッドを返します。true最初の文字など、ディレクトリの区切り記号をが場合"\"、またはパスがドライブ文字とコロン (:) で始まる場合。The IsPathRooted method returns true if the first character is a directory separator character such as "\", or if the path starts with a drive letter and colon (:). たとえばを返しますtruepathなどの文字列"\\MyDir\\MyFile.txt"、"c:\\MyDir"、または"C:MyDir"。For example, it returns true for path strings such as "\\MyDir\\MyFile.txt", "C:\\MyDir", or "C:MyDir". 返しますfalsepathMyDir というなどの文字列。It returns false for path strings such as "MyDir".

このメソッドは、パスまたはファイル名が存在することを検証しません。This method does not verify that the path or file name exists.

共通 I/O タスクの一覧は、 共通 I/O タスク を参照してください。For a list of common I/O tasks, see Common I/O Tasks.

こちらもご覧ください

適用対象