Share via


HOW TO:在 Visual Basic 中判斷檔案的建立時間

更新:2007 年 11 月

My.Computer.FileSystem.GetFileInfo 方法 可以用來取得 FileInfo 物件,物件含有關於指定的檔案之資訊。

您可以使用 CreationTime 或 CreationTimeUtc 屬性取得或設定上次存取時間。CreationTimeUtc 是以國際標準時間 (UTC) 顯示時間。如需詳細資訊,請參閱日期和時間格式字串

注意事項:

根據您目前使用的設定或版本,您所看到的對話方塊選項,以及功能表命令的名稱和位置,可能會與 [說明] 中描述的不同。撰寫這個說明網頁時已將 [一般開發設定] 納入考慮。若要變更設定,請從 [工具] 功能表中選擇 [匯入和匯出設定]。如需詳細資訊,請參閱 Visual Studio 設定

若要判斷檔案的建立時間

  • 使用 GetFileInfo 方法傳回檔案的 FileInfo 物件,可用來查詢資訊。這個範例會取得 Testfile.txt 的 FileInfo 物件,並使用 CreationTime 屬性顯示建立時間。

    Dim infoReader As System.IO.FileInfo
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\testfile.txt")
    MsgBox("File was created on " & infoReader.CreationTime)
    

請參閱

工作

HOW TO:在 Visual Basic 中判斷檔案屬性

HOW TO:在 Visual Basic 中判斷上一次存取檔案的時間

參考

My.Computer.FileSystem 物件

My.Computer.FileSystem.GetFileInfo 方法

其他資源

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