I am trying to copy files from one directory to another and test based upon the file creation date.
File.Copy(fileName, directory + fileNameOnly, true);
The problem occurs later in my program when I checked the creation date to ensure it is no more than 5 days old.
FileInfo file = new FileInfo(fileName);
if (file.CreationTime.AddHours(120) < DateTime.Now) {}
I have seen that the creation date when copied back is set to 1980-01-01. This is not useful for my requirements as I would like maintain the creation date from the original file. Is there another method of comparing the dates or is it the copy that loses the creation date value.
I guess my question is, how can I maintain the Creation Date?
Windows does not preserve the creation_time in the copied file of the original file. The modification time is copied. The creation time is always the current system time.
If you copy a file from C:\fat16 to D:\NTFS, it keeps the same modified date and time but changes the created date and time to the current date and time. If you move a file from C:\fat16 to D:\NTFS, it keeps the same modified date and time and keeps the same created date and time.
You can show the "creation date" that is stored for files in the Windows Explorer easily: Switch Windows Explorer to column view, right click a column header and and in the context menu that pops up select "Creation Date" for enabling the additional column.
Use the File.SetCreationTime method after you copy the file.
You can get the source file's creation time with File.GetCreationTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With