VB.net Program to Set the Last Access Time of a Specified File or Directory

You are currently viewing VB.net Program to Set the Last Access Time of a Specified File or Directory

VB.Net program to set the last access time of a specified file or directory

'VB.Net program to set the last access time 
'of a specified file.

Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim dt1 As DateTime

            Console.WriteLine("Time before set last access time:")
            dt1 = File.GetLastAccessTime("sample.txt")
            Console.WriteLine("Last Access Time of file(sample.txt) : " & dt1)

            File.SetLastAccessTime("sample.txt", DateTime.Now)

            Console.WriteLine("Time After set last access time:")

            dt1 = File.GetLastAccessTime("sample.txt")
            Console.WriteLine("Last Access Time of file(sample.txt) : " & dt1)

        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module
Time before set last access time:
Last Access Time of file(sample.txt) : 09-01-2021 14:35:38
Time After set last access time:
Last Access Time of file(sample.txt) : 09-01-2021 21:13:35
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply