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。檔案的名稱與路徑。必要項。
傳回值
例外狀況
下列情形可能會造成例外狀況:
路徑名稱錯誤。例如,它包含無效字元或只是泛空白字元 (ArgumentException)
檔案名稱以斜線結束 (ArgumentException)。
檔案不存在,或檔案為 Nothing (ArgumentNullException)。
路徑在字串中間包含一個冒號 (NotSupportedException)。
路徑太長 (PathTooLongException)。
使用者缺乏必要的使用權限 (SecurityException)。
使用者缺少對檔案的 ACL (存取控制清單) 存取 (UnauthorizedAccessException)。
備註
若檔案不存在並不會擲出例外狀況,而是會在第一次存取物件的屬性 (Property) 時擲出例外狀況。
工作
下表列出包含 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 執行階段程式庫 (在 Microsoft.VisualBasic.dll 中)
依專案類型的可用性
專案類型 |
是否可用 |
---|---|
Windows 應用程式 |
是 |
類別庫 |
是 |
主控台應用程式 |
是 |
Windows 控制項程式庫 |
是 |
Web 控制項程式庫 |
是 |
Windows 服務 |
是 |
網站 |
是 |
使用權限
下列使用權限可能為必要:
使用權限 |
描述 |
---|---|
控制存取檔案和資料夾的功能。關聯的列舉型別:Unrestricted。 |