How to get File Created Date and Modified Date [du

2020-02-26 13:36发布

I have an .NET EXE file . I want to find the file created date and modified date in C# application. Can do it through reflection or with IO stream?

6条回答
混吃等死
2楼-- · 2020-02-26 14:13

Use :

FileInfo fInfo = new FileInfo('FilePath');
var fFirstTime = fInfo.CreationTime;
var fLastTime = fInfo.LastWriteTime;
查看更多
男人必须洒脱
3楼-- · 2020-02-26 14:14

You could use below code:

DateTime creation = File.GetCreationTime(@"C:\test.txt");
DateTime modification = File.GetLastWriteTime(@"C:\test.txt");
查看更多
Fickle 薄情
4楼-- · 2020-02-26 14:14

You can do that using FileInfo class:

FileInfo fi = new FileInfo("path");
var created = fi.CreationTime;
var lastmodified = fi.LastWriteTime;
查看更多
Explosion°爆炸
5楼-- · 2020-02-26 14:21

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");
查看更多
男人必须洒脱
6楼-- · 2020-02-26 14:34

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);
查看更多
手持菜刀,她持情操
7楼-- · 2020-02-26 14:39

File.GetLastWriteTime to Get last modified

File.CreationTime to get Created time

查看更多
登录 后发表回答