Delete files older than a date

后端 未结 3 486
我寻月下人不归
我寻月下人不归 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条回答
  •  -上瘾入骨i
    2020-12-20 20:57

    I guess an additional problem must be in

    File.Delete(string.Format("{0}/{1}", directory, file));
    

    Your file is of type FileSystemInfo. Maybe you wanted to use file.Name. Example: let's say directory is "c:\" and file points to "c:\myfile.log", your code will try to delete "c:/c:\myfile.log". It's hard for me to guess what exactly you have in these variables.

    Correct replacement is suggested by @HenkHolterman:

    file.Delete();
    

提交回复
热议问题