C# – Return FileWriteTime of File

email me

This returns the last write time of a file.

Compiled in Visual Studio 2017.

using System;
using System.IO;

namespace return_timestamp
{
class Touch
{
static void Main(string[] args)
{
string fileName = "c:\\setup\\setup.exe";

FileInfo fileinfo = new FileInfo(fileName);
touchFile(fileinfo);
Console.ReadKey();

}

static void touchFile(FileSystemInfo filename)
{
Console.WriteLine("File name: {0}", filename.FullName);
try
{
filename.CreationTime = filename.LastWriteTime;
Console.Write("\nTimestamp: ");
Console.Write(filename.CreationTime);

}
catch (Exception x)
{
Console.WriteLine("Error: {0}", x.Message);
}
}
}
}

 

Notes

FileInfo Class

FileSystemInfo.LastWriteTime Property

Further research

DateTimeOffset.FromFileTime(Int64) Method