Delete files older than 3 months old in a directory using .NET

前端 未结 18 2078
醉话见心
醉话见心 2020-12-02 06:31

I would like to know (using C#) how I can delete files in a certain directory older than 3 months, but I guess the date period could be flexible.

Just to be clear:

18条回答
  •  一向
    一向 (楼主)
    2020-12-02 06:56

    you just need FileInfo -> CreationTime

    and than just calculate the time difference.

    in the app.config you can save the TimeSpan value of how old the file must be to be deleted

    also check out the DateTime Subtract method.

    good luck

提交回复
热议问题