C# Program to Get Last Write Time of File or Directory

You are currently viewing C# Program to Get Last Write Time of File or Directory

C# program to get last write time of file or directory

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            DateTime dt1;
            DateTime dt2;

            dt1 = File.GetLastWriteTime("ABC.TXT");
            Console.WriteLine("Last Write Time of file(ABC.TXT) : " + dt1);

            dt2 = File.GetLastWriteTime("mydir");
            Console.WriteLine("Last Write Time of directory(mydir) : " + dt2);
        }
    }
}

Output

Last Write Time of file(ABC.TXT) : 10/31/2017 9:38:13 PM
Last Write Time of directory(mydir) : 10/31/2017 9:08:23 PM

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