Hello there guys,
I've been trying to figure out a way to delete all folders & sub-folders which are older than "XX" amount of days .. but without luck. I've googled my ass off and still cannot seem to get it working. I'm still new at C# so hence why I'm here, asking for your help!
Here are my attempts:
.. I guess this one ^ wouldn't even work the way I wanted it, because it deletes only files?
And for this one, I have no clue why it doesn't work ..
You help would be appreciated! Thanks in advance!
-kind regards-
Gomo
I've been trying to figure out a way to delete all folders & sub-folders which are older than "XX" amount of days .. but without luck. I've googled my ass off and still cannot seem to get it working. I'm still new at C# so hence why I'm here, asking for your help!
Here are my attempts:
C#:
if (checkBox2.Checked == true)
{
DirectoryInfo backups = new DirectoryInfo(Backup);
foreach (FileInfo file in backups.GetFiles())
if (file.LastWriteTime < DateTime.Now.AddDays(-30))
file.Delete();
}
C#:
if (checkBox2.Checked == true)
{
string[] backups = Directory.GetFiles(Backup);
foreach (string folders in backups)
{
DirectoryInfo fi = new DirectoryInfo(folders);
if (fi.LastAccessTime < DateTime.Now.AddDays(-30))
fi.Delete();
}
}
You help would be appreciated! Thanks in advance!
-kind regards-
Gomo