更新:2007 年 11 月
返回指定路径的 DirectoryInfo 对象。
' Usage
Dim value As System.IO.DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(directory)
' Declaration
Public Function GetDirectoryInfo( _
   ByVal directory As String _
) As System.IO.DirectoryInfo
参数
- directory
 String。目录的路径。必选。
返回值
异常
以下情况可能会导致异常:
- 目录路径由于以下原因之一而无效:它是零长度字符串;它仅包含空白;它包含无效字符;或者它是一个设备路径(以 \\.\ 开头)(ArgumentException)。 
- 目录路径无效,因为它是 Nothing (ArgumentNullException)。 
- 目录路径超过了系统定义的最大长度 (PathTooLongException)。 
- 目录路径中的文件名或目录名包含冒号 (:),或格式无效 (NotSupportedException)。 
- 该用户缺少查看该目录路径所必需的权限 (SecurityException)。 
备注
如果目录不存在,则在首次访问 DirectoryInfo 对象的属性之前不会引发异常。
任务
下表列出了涉及 My.Computer.FileSystem.GetDirectoryInfo 方法的任务的示例。
| 要执行的操作 | 请参见 | 
|---|---|
| 确定目录的创建时间 | |
| 确定目录是否为只读 | 
示例
此示例获取目录 C:\Documents and Settings 的 DirectoryInfo 对象,并显示该目录的创建时间、上次访问时间和上次写入时间。
Dim getInfo As System.IO.DirectoryInfo
getInfo = My.Computer.FileSystem.GetDirectoryInfo _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments)
MsgBox("The directory was created at " & getInfo.CreationTime)
MsgBox("The directory was last accessed at " & getInfo.LastAccessTime)
MsgBox("The directory was last written to at " & getInfo.LastWriteTime)
要求
命名空间:Microsoft.VisualBasic.MyServices
类:FileSystemProxy(提供对 FileSystem 的访问)
**程序集:**Visual Basic Runtime Library(位于 Microsoft.VisualBasic.dll 中)
按项目类型列出可用性
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 是 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 是 | 
| Web 控件库 | 是 | 
| Windows 服务 | 是 | 
| 网站 | 是 | 
权限
以下权限可能是必需的:
| 权限 | 说明 | 
|---|---|
| 控制访问文件和文件夹的能力。关联的枚举:Unrestricted。 |