Delete files older than a date

后端 未结 3 497
我寻月下人不归
我寻月下人不归 2020-12-20 20:09

I am currently working on a c# program where I check the creation time of a file and delete it if the file is older than 2 days. I have the following code snippet that shoul

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 20:50

    file.Delete does make more sense than File.Delete(path) and Path.Combine() makes a lot more sense than using string.Format.

    I've stumbled across this answer, don't know why I didn't find it before hand after spending ages on google, but this appears to have fixed the problem. DateTime.Compare how to check if a date is less than 30 days old?. The other problem was that I was using the file creation time but for my scenario it made more sense to use lastWriteTime.date.

提交回复
热议问题