VB.Net program to set file creation time

Here, we are going to learn how to set file creation time in VB.Net?
Submitted by Nidhi, on January 08, 2021

Here, we will use SetCreationTime() method of the File class to set the new creation time of the specified file and then print the old and new file creation time on the console screen.

Program/Source Code:

The source code to set file creation time is given below. The given program is compiled and executed successfully.

'VB.Net program to set file creation time.

Imports System.IO

Module Module1
    Sub Main()
            Dim D1 As DateTime = File.GetCreationTime("sample.txt")
            Console.WriteLine("Old File Creation Time : " & D1.ToString())

            Dim D2 As DateTime = New DateTime(2017, 12, 25, 19, 45, 10)
            File.SetCreationTime("sample.txt", D2)

            Dim D3 As DateTime = File.GetCreationTime("sample.txt")
            Console.WriteLine("New File Creation Time : " + D3.ToString())

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


Old File Creation Time : 06-01-2021 22:19:11
New File Creation Time : 25-12-2017 19:45:10
Press any key to continue . . .


In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program. Here, we get the file creation time of "sample.txt" file using GetCreationTime() method and set new file creation time using SetCreationTime(). After that print the old and new file creation time on the console screen.

If the specified file does not exist in the computer system then a file not found exception gets generated and prints the appropriate message on the console screen.

VB.Net File Handling Programs »



Comments and Discussions



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

© some rights reserved.