VB.Net program to print file creation time

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

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

Program/Source Code:

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

'VB.Net program to print file creation time.

Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim D As DateTime = File.GetCreationTime("sample.txt")
            Console.WriteLine("File Creation Time : " & D.ToString())
        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module

Output:

File Creation Time : 06-01-2021 22:19:11
Press any key to continue . . .

Explanation:

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 the "sample.txt" file using GetCreationTime() method and then assigned it to the object of the DateTime class and print the creation time on the console screen.

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





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.