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

The My.Computer.FileSystem.GetFileInfo Method can be used to get a FileInfo object, which contains information about the specified file.

You can use the LastAccessTime or the LastAccessTimeUtc property to get or set the last access time. LastAccessTimeUtc displays the time in Coordinated Universal Time (UTC). For more information, see Date and Time Format Strings.

Note

The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is described in Help, depending on your active settings or edition. This Help page was written with General Development Settings in mind. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To determine a file's last accessed 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 LastAccessTime 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 accessed on " & infoReader.LastAccessTime)
    

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

My.Computer.FileSystem Object

My.Computer.FileSystem.GetFileInfo Method

Other Resources

Creating, Deleting, and Moving Files and Directories in Visual Basic

File, Directory, and Drive Properties in Visual Basic