How to: Determine a File's Last Modified Time in Visual Basic

The GetFileInfo method can be used to get a FileInfo object, which contains information about the specified file.

You can use the LastWriteTime or the LastWriteTimeUtc property to get or set the last time the file was modified. LastWriteTimeUtc displays the time in Coordinated Universal Time (UTC). For more information, see Standard Date and Time Format Strings.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To determine a file's last modified time

  • Use the GetFileInfo method to return a FileInfo object for the file, which can be queried for information. This example gets a FileInfo object for Testfile.txt and uses the LastWriteTime property to display the last access time.

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

See Also

Tasks

How to: Determine a File's Attributes in Visual Basic

How to: Determine a File's Creation Time in Visual Basic

Reference

FileSystem

GetFileInfo

Other Resources

File, Directory, and Drive Properties in Visual Basic