我有一个.NET EXE 文件。 我想在 C # 应用程序中找到创建日期和修改日期的文件。可以通过反射或 IO 流做到这一点?
You can do that using FileInfo class:
FileInfo
FileInfo fi = new FileInfo("path"); var created = fi.CreationTime; var lastmodified = fi.LastWriteTime;
File.GetLastWriteTime to Get last modified
File.GetLastWriteTime
File.CreationTime to get Created time
File.CreationTime
Use :
FileInfo fInfo = new FileInfo('FilePath'); var fFirstTime = fInfo.CreationTime; var fLastTime = fInfo.LastWriteTime;
You can use this code to see the last modified date of a file.
DateTime dt = File.GetLastWriteTime(path);
And this code to see the creation time.
DateTime fileCreatedDate = File.GetCreationTime(@"C:\Example\MyTest.txt");
You could use below code:
DateTime creation = File.GetCreationTime(@"C:\test.txt"); DateTime modification = File.GetLastWriteTime(@"C:\test.txt");
File.GetLastWriteTime Method
Returns the date and time the specified file or directory was last written to.
string path = @"c:\Temp\MyTest.txt"; DateTime dt = File.GetLastWriteTime(path);
For create time File.GetCreationTime Method
DateTime fileCreatedDate = File.GetCreationTime(@"C:\Example\MyTest.txt"); Console.WriteLine("file created: " + fileCreatedDate);