创建日期和File.Copy问题 [英] 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);
后出现的问题,在我的计划,当我检查创建日期,以确保其不超过5天。
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) {}
我已经看到,当复制回创建日期设置为1980-01-01。这不是对我的要求非常有用,因为我想保持了原始文件的创建日期。有没有比较日期的另一种方法还是那个失去的创建日期值的副本。
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?
推荐答案
使用的<一个href="http://msdn.microsoft.com/en-us/library/system.io.file.setcreationtime.aspx">File.SetCreationTime你复制后的文件的方法。
你可以在源文件的创建时间<一个href="http://msdn.microsoft.com/en-us/library/system.io.file.getcreationtime.aspx">File.GetCreationTime
Use the File.SetCreationTime method after you copy the file.
You can get the source file's creation time with File.GetCreationTime
这篇关于创建日期和File.Copy问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!