Path.IsPathRooted メソッドとは何? わかりやすく解説 Weblio辞書 (original) (raw)
このメソッドは、パス名またはファイル名が存在することを検査しません。
IsPathRooted は、"\\MyDir\\MyFile.txt" や "C:\\MyDir" などの path 文字列に対しては true を返します。"MyDir" などの path 文字列に対しては、**false** を返します。
このメソッドの使用例については、以下の「使用例」を参照してください。その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
| 実行するタスク | 参考例があるトピック |
|---|---|
| テキスト ファイルを作成する。 | 方法 : ファイルにテキストを書き込む |
| テキスト ファイルに書き込む。 | 方法 : ファイルにテキストを書き込む |
| テキスト ファイルから読み取る。 | 方法 : ファイルからテキストを読み取る |
| ファイルの絶対パスを取得する。 | GetFullPath |
| パスからディレクトリ名だけを取得する。 | GetDirectoryName |
| ディレクトリが存在するかどうかを判別する。 | Exists |
IsPathRooted プロパティの使用方法を次のコード例に示します。
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);