find the last accessed date of a csv file in csharp

Here is the code snippet to find the last accessed date of a csv file in C#:

main.cs
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string filePath = @"C:\example\file.csv";
        
        // Get the last access time of the file
        DateTime lastAccessTime = File.GetLastAccessTime(filePath);
        
        // Output the last access time
        Console.WriteLine("Last accessed date of {0}: {1}", Path.GetFileName(filePath), lastAccessTime.ToString("dd/MM/yyyy HH:mm:ss"));
    }
}
458 chars
17 lines

In the above code, we first specify the file path of the CSV file. We then use the File.GetLastAccessTime() method to get the last access time of the file. Finally, we output the last access time using Console.WriteLine(). The date format used in this example is "dd/MM/yyyy HH:mm:ss", but you can use any format that suits your needs.

gistlibby LogSnag