More complex directory deletion

This commit is contained in:
Timothy Baldridge 2021-12-19 14:52:06 -07:00
parent ac54d8d89d
commit a3e545281e
2 changed files with 18 additions and 3 deletions

View File

@ -187,7 +187,24 @@ public static class AbsolutePathExtensions
{
if (!path.DirectoryExists()) return;
if (dontDeleteIfNotEmpty && (path.EnumerateFiles().Any() || path.EnumerateDirectories().Any())) return;
Directory.Delete(ToNativePath(path), true);
foreach (string directory in Directory.GetDirectories(path.ToString()))
{
DeleteDirectory(directory.ToAbsolutePath(), dontDeleteIfNotEmpty);
}
try
{
Directory.Delete(path.ToString(), true);
}
catch (IOException)
{
Directory.Delete(path.ToString(), true);
}
catch (UnauthorizedAccessException)
{
Directory.Delete(path.ToString(), true);
}
}
public static bool DirectoryExists(this AbsolutePath path)

View File

@ -91,8 +91,6 @@ public class AuthorFiles
public async Task DeleteFile(FileDefinition definition)
{
var folder = AuthorFilesLocation.Combine(definition.MungedName);
foreach (var file in folder.EnumerateFiles())
file.Delete();
folder.DeleteDirectory();
}