find the last accessed date of a directory in csharp

You can find the last accessed date of a directory in C# using the DirectoryInfo class from the System.IO namespace. Here's an example:

main.cs
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string directoryPath = @"C:\Users\john\Documents";
        DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);

        DateTime lastAccessTime = directoryInfo.LastAccessTime;
        Console.WriteLine($"Last accessed: {lastAccessTime}");
    }
}
357 chars
15 lines

In the example above, we create a DirectoryInfo object with the path of the directory we want to check. We can then access the LastAccessTime property of this object, which gives us the date and time when the directory was last accessed.

gistlibby LogSnag