共用方式為


My.Computer.FileSystem.GetFileInfo 方法

更新: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。檔案的名稱與路徑。必要項。

傳回值

FileInfo

例外狀況

下列情形可能會造成例外狀況:

備註

若檔案不存在並不會擲出例外狀況,而是會在第一次存取物件的屬性 (Property) 時擲出例外狀況。

工作

下表列出包含 My.Computer.FileSystem.GetFileInfo 方法的工作範例。

若要

請參閱

取得檔案的相關資訊

HOW TO:在 Visual Basic 中取得檔案的相關資訊

判斷檔案的名稱與路徑

HOW TO:在 Visual Basic 中剖析檔案路徑

範例

此範例會擷取 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 執行階段程式庫 (在 Microsoft.VisualBasic.dll 中)

依專案類型的可用性

專案類型

是否可用

Windows 應用程式

類別庫

主控台應用程式

Windows 控制項程式庫

Web 控制項程式庫

Windows 服務

網站

使用權限

下列使用權限可能為必要:

使用權限

描述

FileIOPermission

控制存取檔案和資料夾的功能。關聯的列舉型別:Unrestricted

如需詳細資訊,請參閱程式碼存取安全性要求使用權限

請參閱

工作

逐步解說:在 Visual Basic 中管理檔案和目錄

參考

My.Computer.FileSystem 物件

System.IO.FileInfo

FileSystem.GetFileInfo

其他資源

Visual Basic 中的檔案、目錄和磁碟機屬性