FileSystemProxy.GetFileInfo(String) 方法

定義

回傳 FileInfo 指定檔案的物件。

public:
 System::IO::FileInfo ^ GetFileInfo(System::String ^ file);
public System.IO.FileInfo GetFileInfo(string file);
member this.GetFileInfo : string -> System.IO.FileInfo
Public Function GetFileInfo (file As String) As FileInfo

參數

file
String

檔案名稱和路徑。

傳回

FileInfo 物件用於指定檔案。

例外狀況

這條路徑名稱有問題。 例如,它包含無效字元或僅有空白。 檔案名稱後面有斜線標記。

fileNothing 空字串。

路徑中包含一個冒號位於字串中間。

路太長了。

使用者缺乏必要的權限。

使用者無法存取該檔案的 ACL(存取控制清單)。

範例

此範例會 System.IO.FileInfo 取得該檔案 MyLogFile.log 的物件,並用它回報檔案的全名、最後存取時間及長度。

Dim 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 & ".")

備註

若檔案不存在,則不會拋出例外;而是在物件屬性首次被存取時拋出。

下表列出一個涉及此 My.Computer.FileSystem.GetFileInfo 方法的任務範例。

看!
確定檔案名稱與路徑 如何解析檔案路徑

適用於

另請參閱