Path.GetPathRoot メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim path As String Dim returnValue As String returnValue = Path.GetPathRoot(path)
戻り値
path にルート ディレクトリ情報が含まれている場合は、"C:\" などのルート ディレクトリを含む文字列、path が null 参照 (Visual Basic では Nothing) の場合は null 参照 (Visual Basic では Nothing)、path にルート ディレクトリ情報が含まれていない場合には空の文字列。


.NET Framework では、"\\.\PHYSICALDRIVE0" など、デバイス名を指定したパスを使用して物理ディスクに直接アクセスすることはできません。
このメソッドは、パス名またはファイル名が存在することを検査しません。
このメソッドで返される、有効な文字列のパターンは次のとおりです。
このメソッドの使用例については、以下の「使用例」を参照してください。その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
GetExtension | |
GetFullPath | |
GetFileName | |
GetFileNameWithoutExtension | |
GetDirectoryName | |
ChangeExtension | |

GetPathRoot メソッドの使用方法を次のコード例に示します。
Dim pathname As String = "\mydir\" Dim fileName As String = "myfile.ext" Dim fullPath As String = "C:\mydir\myfile.ext" Dim pathnameRoot As String pathnameRoot = Path.GetPathRoot(pathname) Console.WriteLine("GetPathRoot('{0}') returns '{1}'", pathname, pathnameRoot) pathnameRoot = Path.GetPathRoot(fileName) Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fileName, pathnameRoot) pathnameRoot = Path.GetPathRoot(fullPath) Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fullPath, pathnameRoot) ' This code produces output similar to the following: ' ' GetPathRoot('\mydir\') returns '\' ' GetPathRoot('myfile.ext') returns '' ' GetPathRoot('C:\mydir\myfile.ext') returns 'C:\'
string path = @"\mydir\"; string fileName = "myfile.ext"; string fullPath = @"C:\mydir\myfile.ext"; string pathRoot; pathRoot = Path.GetPathRoot(path); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", path, pathRoot); pathRoot = Path.GetPathRoot(fileName); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fileName, pathRoot); pathRoot = Path.GetPathRoot(fullPath); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fullPath, pathRoot); // This code produces output similar to the following: // // GetPathRoot('\mydir\') returns '\' // GetPathRoot('myfile.ext') returns '' // GetPathRoot('C:\mydir\myfile.ext') returns 'C:\'
String^ path = "\\mydir\\"; String^ fileName = "myfile.ext"; String^ fullPath = "C:\\mydir\\myfile.ext"; String^ pathRoot; pathRoot = Path::GetPathRoot( path ); Console::WriteLine( "GetPathRoot('{0}') returns '{1}'", path, pathRoot ); pathRoot = Path::GetPathRoot( fileName ); Console::WriteLine( "GetPathRoot('{0}') returns '{1}'", fileName, pathRoot ); pathRoot = Path::GetPathRoot( fullPath ); Console::WriteLine( "GetPathRoot('{0}') returns '{1}'", fullPath, pathRoot );
String path = "\\mydir\\"; String fileName = "myfile.ext"; String fullPath = "C:\\mydir\\myfile.ext"; String pathRoot; pathRoot = Path.GetPathRoot(path); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", path, pathRoot); pathRoot = Path.GetPathRoot(fileName); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fileName, pathRoot); pathRoot = Path.GetPathRoot(fullPath); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fullPath, pathRoot);
var path : String = "\\mydir\\"; var fileName : String = "myfile.ext"; var fullPath : String = "C:\\mydir\\myfile.ext"; var pathRoot : String; pathRoot = Path.GetPathRoot(path); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", path, pathRoot); pathRoot = Path.GetPathRoot(fileName); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fileName, pathRoot); pathRoot = Path.GetPathRoot(fullPath); Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fullPath, pathRoot);

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からPath.GetPathRoot メソッドを検索する場合は、下記のリンクをクリックしてください。

- Path.GetPathRoot メソッドのページへのリンク