Path.GetPathRoot メソッドとは? わかりやすく解説

Path.GetPathRoot メソッド

指定したパスルート ディレクトリ情報取得します

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentException

path に、InvalidPathChars で定義されている無効な文字1 つ以上含まれているか、ワイルドカード文字含まれています。

または

String.Empty が path渡されました。

解説解説

.NET Framework では、"\\.\PHYSICALDRIVE0" など、デバイス名を指定したパス使用して物理ディスク直接アクセスすることはできません。

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

このメソッド返される有効な文字列のパターン次のとおりです。

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

使用例使用例

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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Path.GetPathRoot メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Path.GetPathRoot メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS