更新:2007 年 11 月
返回指定文件的 FileInfo 对象。
' Usage
Dim value As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(file)
' Declaration
Public Function GetFileInfo( _
   ByVal file As String _
) As System.IO.FileInfo
参数
- file
 String。文件的名称和路径。必选。
返回值
异常
以下情况可能会导致异常:
- 路径名格式不正确。例如,它包含无效字符或仅仅是空白 (ArgumentException)。 
- 文件名具有尾随斜杠标记 (ArgumentException)。 
- 该文件不存在或者为 Nothing (ArgumentNullException)。 
- 该路径在字符串中间包含一个冒号 (NotSupportedException)。 
- 路径太长 (PathTooLongException)。 
- 用户缺少必要的权限 (SecurityException)。 
- 用户缺少对该文件的 ACL(访问控制列表)访问 (UnauthorizedAccessException)。 
备注
如果该文件不存在,则不会引发异常,而在第一次访问对象的属性时将会引发异常。
任务
下表列出了涉及 My.Computer.FileSystem.GetFileInfo 方法的任务的示例。
| 要执行的操作 | 请参见 | 
|---|---|
| 获取有关文件的信息 | |
| 确定文件的名称和路径 | 
示例
此示例检索文件 MyLogFile.log 的 System.IO.FileInfo 对象,并使用该对象报告文件的全名、上次访问时间和长度。
Dim information As System.IO.FileInfo
information = My.Computer.FileSystem.GetFileInfo("C:\MyLogFile.log")
MsgBox("The file's full name is " & information.FullName & ".")
MsgBox("Last access time is " & information.LastAccessTime & ".")
MsgBox("The length is " & information.Length & ".")
要求
命名空间:Microsoft.VisualBasic.MyServices
类:FileSystemProxy(提供对 FileSystem 的访问)
**程序集:**Visual Basic Runtime Library(位于 Microsoft.VisualBasic.dll 中)
按项目类型列出可用性
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 是 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 是 | 
| Web 控件库 | 是 | 
| Windows 服务 | 是 | 
| 网站 | 是 | 
权限
以下权限可能是必需的:
| 权限 | 说明 | 
|---|---|
| 控制访问文件和文件夹的能力。关联的枚举:Unrestricted。 |