C Simple Read Change File Creation Modification and Access Time Method

  • 2021-07-22 11:04:04
  • OfStack

In this paper, the example of C # simple reading, changing the file creation, modification and access time method. Share it for your reference. The details are as follows:


FileInfo fi = new FileInfo("C:\\test.txt");
Console.WriteLine(fi.CreationTime.ToString());
Console.WriteLine(fi.LastWriteTime.ToString());
Console.WriteLine(fi.LastAccessTime.ToString());
//  Change (set) the creation, modification and access time of files 
File.SetCreationTime("C:\\test.txt", DateTime.Now.AddYears(-1));
File.SetLastWriteTime("C:\\test.txt", DateTime.Now.AddYears(-2));
File.SetLastAccessTime("C:\\test.txt", DateTime.Now.AddYears(-3));

I hope this article is helpful to everyone's C # programming.


Related articles: