注意:如果我现在创建文件,这也必须工作,那么该文件将不会一小时到几秒钟.
System.IO.File.GetCreationTime(filename);
要获取文件的创建时间,请参阅@L_301_0@了解更多详细信息和示例.
那么你可以做一些像:
public bool IsBelowThreshold(string filename,int hours) { var threshold = DateTime.Now.AddHours(-hours); return System.IO.File.GetCreationTime(filename).AddHours(-hours) <= threshold; }