Path.IsPathRooted メソッドとは何? わかりやすく解説 Weblio辞書 (original) (raw)

このメソッドは、パス名またはファイル名存在することを検査しません。

IsPathRooted は、"\\MyDir\\MyFile.txt" や "C:\\MyDir" などの path 文字列に対してtrue返します。"MyDir" などの path 文字列に対しては、**false** を返します

このメソッド使用例については、以下の「使用例」を参照してくださいその他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します

実行するタスク 参考例があるトピック
テキスト ファイル作成する 方法 : ファイルテキスト書き込む
テキスト ファイル書き込む 方法 : ファイルテキスト書き込む
テキスト ファイルから読み取る 方法 : ファイルかテキスト読み取る
ファイル絶対パス取得する GetFullPath
パスからディレクトリ名だけを取得する GetDirectoryName
ディレクトリ存在するかどうか判別する Exists

IsPathRooted プロパティ使用方法次のコード例示します

Visual Basic

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

C#

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

C++

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() );

J#

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));

JScript

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);