开发者

Creation Date and File.Copy Issue

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.

FileInf开发者_StackOverflow中文版o 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜