首页 > 代码库 > C#获取文件时间
C#获取文件时间
在NTFS下,文件的创建及修改时间可以精确到毫秒,以下是测试过程。
DirectoryInfo diSource = new DirectoryInfo(@"C:\Users\不告诉你\Desktop\Old");
FileInfo File1 = diSource.GetFiles()[0];
FileInfo File2 = diSource.GetFiles()[1];
FileInfo firstfile=diSource.GetFiles()[0];
//Console.WriteLine(firstfile.Name + ":" + firstfile.CreationTime.ToString("hh.mm.ss.ffffff"));
foreach(FileInfo file in diSource.GetFiles())
{
Console.WriteLine(file.Name + ":" + file.LastWriteTime.ToString("hh.mm.ss.fffffff"));
//if (firstfile.CreationTime > file.CreationTime)
//{
// Console.WriteLine(file.Name + ":" + file.CreationTime.ToString("hh.mm.ss.fffffff"));
// firstfile = file;
//}
}
//if (File1.CreationTime < File2.CreationTime)
// Console.WriteLine(File1.FullName);
//else Console.WriteLine(File2.FullName+":"+File2.LastWriteTime.);
// Console.WriteLine("the earliest file is" +firstfile.Name + ":" + firstfile.CreationTime.ToString("hh.mm.ss.ffffff"));
Console.Read();
C#获取文件时间