I have code that looks for empty directories that are older than 1 hour and deletes them
foreach (DirectoryInfo __dir in _directories)
{
if (!__dir.EnumerateFiles().Any() && __dir.LastWriteTime < DateTime.Now.AddHours(-1))
{
Directory.Delete(__dir.FullName)
}
}
That throws an exception saying access to the directory path is denied. However I'm able to manually delete the same directory through file explorer.
I tried what other people suggested (setting attributes to normal), but that didn't work.
I tried FileAttributes.Normal;
and ~FileAttributes.ReadOnly;
Neither of them work.
I also tried setting access control to full control of the directory I'm trying to delete as well as it's parent directories.