Freigeben über


Path.IsPathRooted-Methode

Ruft einen Wert ab, der angibt, ob die angegebene Pfadzeichenfolge absolute oder relative Pfadinformationen enthält.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function IsPathRooted ( _
    path As String _
) As Boolean
'Usage
Dim path As String
Dim returnValue As Boolean

returnValue = Path.IsPathRooted(path)
public static bool IsPathRooted (
    string path
)
public:
static bool IsPathRooted (
    String^ path
)
public static boolean IsPathRooted (
    String path
)
public static function IsPathRooted (
    path : String
) : boolean

Parameter

  • path
    Der zu testende Pfad.

Rückgabewert

true, wenn path einen absoluten Pfad enthält, andernfalls false.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

path enthält mindestens eins der in InvalidPathChars definierten ungültigen Zeichen oder ein Platzhalterzeichen.

Hinweise

Diese Methode überprüft nicht, ob der Pfad oder Dateiname vorhanden ist.

IsPathRooted gibt true für path-Zeichenfolgen wie "\\MyDir\\MyFile.txt" und "C:\\MyDir" zurück. Sie gibt false für path-Zeichenfolgen wie "MyDir" zurück.

Ein Beispiel für die Verwendung dieser Methode finden Sie im Beispielabschnitt weiter unten. In der folgenden Tabelle sind Beispiele für andere typische oder verwandte E/A-Aufgaben aufgeführt.

Aufgabe

Beispiel in diesem Thema

Erstellen einer Textdatei.

Gewusst wie: Schreiben von Text in eine Datei

Schreiben in eine Textdatei.

Gewusst wie: Schreiben von Text in eine Datei

Lesen aus einer Textdatei.

Gewusst wie: Lesen aus einer Textdatei

Abrufen des voll qualifizierten Pfades einer Datei.

GetFullPath

Nur den Verzeichnisnamen aus einem Pfad abrufen.

GetDirectoryName

Bestimmen, ob ein Verzeichnis vorhanden ist.

Exists

Beispiel

Im folgenden Codebeispiel wird die Verwendung der IsPathRooted-Eigenschaft veranschaulicht.

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
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
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() );
String fileName = "C:\\mydir\\myfile.ext";
String UncPath = "\\\\myPc\\mydir\\myfile";
String relativePath = "mydir\\sudir\\";
boolean result;

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

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

result = Path.IsPathRooted(relativePath);
Console.WriteLine("IsPathRooted('{0}') returns {1}", 
    relativePath, System.Convert.ToString (result));
var fileName : String = "C:\\mydir\\myfile.ext";
var UncPath : String = "\\\\myPc\\mydir\\myfile";
var relativePath : String = "mydir\\sudir\\";
var result : 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);

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Path-Klasse
Path-Member
System.IO-Namespace

Weitere Ressourcen

Datei- und Stream-E/A
Gewusst wie: Lesen aus einer Textdatei
Gewusst wie: Schreiben von Text in eine Datei