Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get File Created Date and Modified Date [duplicate]

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?

like image 602
griffithstratton Avatar asked Apr 23 '14 11:04

griffithstratton


People also ask

How do I find the original date a file was created?

Right click - select Properties. Click the Details tab. Look for the Origin section.

How can a file have a modified date before created date?

What Happened? When copying files to another storage media, Microsoft Windows™ takes the date of copying as the new file date “Created” and not the original creation date or date taken of the files. Therefore, the date “Created” can even be more recent than the date “Modified”.

How can I change the date modified on multiple files?

Select the file(s) you want to modify or press “Ctrl + A” keys to select all added files. Click the “Actions” tab and select “Change file time / Attributes” options. On the resulting popup, you can edit “Accessed”, “Modified” and “Created” timestamps using the arrow for date and time fields.


2 Answers

You could use below code:

DateTime creation = File.GetCreationTime(@"C:\test.txt"); DateTime modification = File.GetLastWriteTime(@"C:\test.txt"); 
like image 198
waitefudge Avatar answered Sep 29 '22 10:09

waitefudge


You can do that using FileInfo class:

FileInfo fi = new FileInfo("path"); var created = fi.CreationTime; var lastmodified = fi.LastWriteTime; 
like image 32
Selman Genç Avatar answered Sep 29 '22 12:09

Selman Genç