FileSystem.GetFileInfo(String) 方法

定義

傳回指定之檔案的 FileInfo 物件。

public:
 static System::IO::FileInfo ^ GetFileInfo(System::String ^ file);
public static System.IO.FileInfo GetFileInfo (string file);
static member GetFileInfo : string -> System.IO.FileInfo
Public Shared 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 方法的工作範例。

收件者 請參閱
判斷檔案的名稱和路徑 如何:在 Visual Basic 中剖析檔案路徑

適用於

另請參閱