-2

I am programing to have a file deleted in X- amount of days:

for (int i = 0; i < 5; i++)
        {
            System.IO.DirectoryInfo fi = new DirectoryInfo(m_strfilename[i].Text);
            if (fi.LastAccessTime < DateTime.Now.AddDays(-Convert.ToInt32(m_dropdown[i].Value)))
                fi.Delete();

I am not quite sure what the issue is with this.

  • try `fi.Delete(true);` – Andy Apr 27 '21 at 21:24
  • 4
    What happened when you tried reading the documentation for `.Delete`? What happened when you tried putting the error message into a search engine? What happened when you tried *reading* the error message? (Since it says "The directory is not empty", and it's an *error message*, maybe it occurred to you that "the issue" is that Windows doesn't want you to delete non-empty directories?) What happened when you tried putting `Windows delete directory` into a search engine? Did you try *anything at all* before coming to Stack Overflow? Please read [ask]. – Karl Knechtel Apr 27 '21 at 21:28
  • I'm sorry, I am new to the website and new to coding as well. I will make sure to trim my questions for everyone in the future. – Lewis Park Apr 27 '21 at 22:10

1 Answers1

0

If directory is not empty it throws exception unless true argument is send with function like fi.Delete(true) on last line. Check: https://learn.microsoft.com/en-us/dotnet/api/system.io.directoryinfo.delete