Thursday, October 19, 2006

FileInfo Class Properties

Interestingly, the creation time, last access time and then last write time properties are all writable:

For example:
FileInfo f = new FileInfo(@"C:\MyFile.txt");
Console.WriteLine(f.CreationTime.ToString());
f.CreationTime = new DateTime(2001, 1, 1, 7, 30, 0);
Console.WriteLine(f.CreationTime.ToString());

Reason given behind this is(Which is quite good also):

If you have a program that effectively modifies a file by simply reading it in, then deletingit and creating a new file with the new contents, then you’d probably want to modify the creation date tomatch the original creation date of the old file.

No comments: