DirectoryInfo.Root プロパティ
パスのルート部分を取得します。
Public ReadOnly Property Root As DirectoryInfo
[C#]
public DirectoryInfo Root {get;}
[C++]
public: __property DirectoryInfo* get_Root();
[JScript]
public function get Root() : DirectoryInfo;
プロパティ値
パスのルートを表す DirectoryInfo オブジェクト。
例外
例外の種類 | 条件 |
---|---|
SecurityException | 呼び出し元に、必要なアクセス許可がありません。 |
解説
このメソッドの使用例については、以下の「使用例」を参照してください。その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
実行するタスク | 参考例があるトピック |
---|---|
ファイルの絶対パスを取得する。 | Path.GetFullPath |
パスからディレクトリ名だけを取得する。 | Path.GetDirectoryName |
ディレクトリ内のファイルを参照する。 | Name |
ディレクトリ内のサブディレクトリを参照する。 | Directory.GetDirectories |
ディレクトリ内のすべてのサブディレクトリにあるすべてのファイルを参照する。 | GetFileSystemInfos |
ディレクトリのサイズを取得する。 | Directory |
ディレクトリの名前を変更、またはディレクトリを移動する。 | Directory.Move |
ファイルが存在するかどうかを判別する。 | Exists |
ディレクトリが存在するかどうかを判別する。 | Exists |
使用例
指定したディレクトリのルートの場所を確認する方法を次の例に示します。
Imports System
Imports System.IO
Public Class MoveToTest
Public Shared Sub Main()
' Make a reference to a directory.
Dim di As New DirectoryInfo("TempDir")
' Create the directory only if it does not already exist.
If di.Exists = False Then
di.Create()
End If
' Create a subdirectory in the directory just created.
Dim dis As DirectoryInfo = di.CreateSubdirectory("SubDir")
Console.WriteLine("The root path of '{0}' is '{1}'", dis.Name, dis.Root)
' Delete the parent directory.
di.Delete(True)
End Sub 'Main
End Class 'MoveToTest
[C#]
using System;
using System.IO;
public class MoveToTest
{
public static void Main()
{
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("TempDir");
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// Create a subdirectory in the directory just created.
DirectoryInfo dis = di.CreateSubdirectory("SubDir");
Console.WriteLine("The root path of '{0}' is '{1}'", dis.Name, dis.Root);
// Delete the parent directory.
di.Delete(true);
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
int main() {
// Make a reference to a directory.
DirectoryInfo* di = new DirectoryInfo(S"TempDir");
// Create the directory only if it does not already exist.
if (!di->Exists)
di->Create();
// Create a subdirectory in the directory just created.
DirectoryInfo* dis = di->CreateSubdirectory(S"SubDir");
Console::WriteLine(S"The root path of '{0}' is '{1}'", dis->Name, dis->Root);
// Delete the parent directory.
di->Delete(true);
}
[JScript]
import System;
import System.IO;
public class MoveToTest {
public static function Main() {
// Make a reference to a directory.
var di : DirectoryInfo = new DirectoryInfo("TempDir");
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// Create a subdirectory in the directory just created.
var dis : DirectoryInfo = di.CreateSubdirectory("SubDir");
Console.WriteLine("The root path of '{0}' is '{1}'", dis.Name, dis.Root);
// Delete the parent directory.
di.Delete(true);
}
}
MoveToTest.Main();
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
.NET Framework セキュリティ:
- FileIOPermission (ファイルやディレクトリから読み取ったり、それらのパスにアクセスしたりするために必要なアクセス許可) FileIOPermissionAccess.Read 、 FileIOPermissionAccess.PathDiscovery (関連する列挙体)
参照
DirectoryInfo クラス | DirectoryInfo メンバ | System.IO 名前空間 | 入出力操作 | ファイルからのテキストの読み取り | ファイルへのテキストの書き込み