ADVERTISEMENT
ADVERTISEMENT

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

Here, we are going to learn how to set the last write time of a specified file in VB.Net?
Submitted by Nidhi, on January 11, 2021

Here, we will use the SetLastWriteTime() method of the File directory to set the last write time of the specified file.

Program/Source Code:

The source code to set the last write time of a specified file is given below. The given program is compiled and executed successfully.

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

Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim dt1 As DateTime

            Console.WriteLine("Time before set last write time:")
            dt1 = File.GetLastWriteTime("sample.txt")
            Console.WriteLine("Last Write Time of file(sample.txt) : " & dt1)

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

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

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

        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module

Output:

Time before set last write time:
Last Write Time of file(sample.txt) : 09-01-2021 21:53:39
Time After set last write time:
Last Write Time of file(sample.txt) : 09-01-2021 21:54:29
Press any key to continue . . .

Explanation:

In the above program, we created the module Module1 that contains the Main() function. The Main() function is the entry point for the program.

Here, we set the last write time of the "sample.txt" file using the SetLastWriteTime() method of the File class. Then we printed the updated last write time on the console screen.

VB.Net File Handling Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.