Alex Rivera | Logout

Creation Date and File.Copy Issue

Asked 2010-12-15T17:21:27.810
12

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?

Edit
Report

1 Answer

19

Use the File.SetCreationTime method after you copy the file.
You can get the source file's creation time with File.GetCreationTime

answered 2010-12-15T17:26:42.000

Your Answer