find the last modified date of a directory in csharp

To find the last modified date of a directory in C#, you can use the DirectoryInfo class which provides methods and properties to retrieve information about directories. Specifically, the LastWriteTime property of the DirectoryInfo class returns the last time the directory was written to.

Here's an example code that demonstrates how to find the last modified date of a directory:

main.cs
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        // Specify the directory path
        string directoryPath = @"C:\Users\JohnDoe\Documents";

        // Create a new instance of DirectoryInfo
        DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);

        // Get the last write time of the directory
        DateTime lastModifiedTime = directoryInfo.LastWriteTime;

        // Print the last modified time of the directory
        Console.WriteLine("Last Modified Time: " + lastModifiedTime);
    }
}
567 chars
21 lines

In the above code, we first specify the directory path for which we want to find the last modified date. Then, we create a new DirectoryInfo instance for that path. Finally, we get the last modified time by accessing the LastWriteTime property of the DirectoryInfo instance.

gistlibby LogSnag