DirectoryInfo.Root 属性
获取路径的根部分。
**命名空间:**System.IO
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property Root As DirectoryInfo
用法
Dim instance As DirectoryInfo
Dim value As DirectoryInfo
value = instance.Root
public DirectoryInfo Root { get; }
public:
property DirectoryInfo^ Root {
DirectoryInfo^ get ();
}
/** @property */
public DirectoryInfo get_Root ()
public function get Root () : DirectoryInfo
属性值
代表路径的根的 DirectoryInfo 对象。
异常
异常类型 | 条件 |
---|---|
调用方没有所要求的权限。 |
备注
下表列出了其他典型或相关的 I/O 任务的示例。
若要执行此操作... |
请参见本主题中的示例... |
---|---|
检索文件的完全限定路径。 |
|
只检索路径中的目录名。 |
|
查看目录中的文件。 |
|
查看目录的子目录。 |
|
查看目录中的所有文件和所有子目录。 |
|
查看目录大小。 |
|
重命名或移动目录。 |
|
确定文件是否存在。 |
|
确定目录是否存在。 |
示例
下面的示例演示了如何确定指定目录的根目录位置。
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
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);
}
}
using namespace System;
using namespace System::IO;
int main()
{
// Make a reference to a directory.
DirectoryInfo^ di = gcnew DirectoryInfo( "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( "SubDir" );
Console::WriteLine( "The root path of '{0}' is '{1}'", dis->Name, dis->Root );
// Delete the parent directory.
di->Delete( true );
}
import System.*;
import System.IO.*;
public class MoveToTest
{
public static void main(String[] args)
{
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("TempDir");
// Create the directory only if it does not already exist.
if (di.get_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.get_Name(), dis.get_Root());
// Delete the parent directory.
di.Delete(true);
} //main
} //MoveToTest
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();
.NET Framework 安全性
- FileIOPermission 用于从文件和目录读取以及用于路径访问。关联的枚举:FileIOPermissionAccess.Read、FileIOPermissionAccess.PathDiscovery
平台
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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
DirectoryInfo 类
DirectoryInfo 成员
System.IO 命名空间