Get FileInfo: file name, file exists, creation time, last write time, last access time : File Properties « File Directory Stream « C# / CSharp Tutorial






using System;
using System.IO;

class MainClass
{
    public static void Main(string[] args)
    {
        FileInfo file = new FileInfo("c:\\test.txt");

        Console.WriteLine("Checking file: " + file.Name);
        Console.WriteLine("File exists: " + file.Exists.ToString());

        if (file.Exists)
        {
            Console.Write("File created: ");
            Console.WriteLine(file.CreationTime.ToString());
            Console.Write("File last updated: ");
            Console.WriteLine(file.LastWriteTime.ToString());
            Console.Write("File last accessed: ");
            Console.WriteLine(file.LastAccessTime.ToString());
        }
        
    }
}
Checking file: test.txt
File exists: True
File created: 24/03/2007 7:23:12 PM
File last updated: 24/03/2007 7:23:12 PM
File last accessed: 25/03/2007 2:04:13 PM








15.8.File Properties
15.8.1.Get FileInfo: file name, file exists, creation time, last write time, last access time
15.8.2.Get FileInfo: file size, file attribute list
15.8.3.Get File creation time and extension name