diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eddd96..9a82133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - X10D: Added `Color.Deconstruct()` - with optional alpha parameter - X10D: Added `Color.GetClosestConsoleColor()` - X10D: Added `DateTime.GetIso8601WeekOfYear()` and `DateTimeOffset.GetIso8601WeekOfYear()` -- X10D: Added `DirectoryInfo.Clear([bool])` +- X10D: Added `DirectoryInfo.Clear()` - X10D: Added `IEnumerable.CountWhereNot(Func)` - X10D: Added `IEnumerable.FirstWhereNot(Func)` - X10D: Added `IEnumerable.FirstWhereNotOrDefault(Func)` diff --git a/X10D/src/IO/DirectoryInfoExtensions.cs b/X10D/src/IO/DirectoryInfoExtensions.cs index 5613a66..5eb0a92 100644 --- a/X10D/src/IO/DirectoryInfoExtensions.cs +++ b/X10D/src/IO/DirectoryInfoExtensions.cs @@ -11,22 +11,8 @@ public static class DirectoryInfoExtensions /// Removes all files and subdirectories in this directory, recursively, without deleting this directory. /// /// The directory to clear. - public static void Clear(this DirectoryInfo directory) - { - directory.Clear(false); - } - - /// - /// Removes all files and subdirectories in this directory, recursively, without deleting this directory. - /// - /// The directory to clear. - /// - /// to throw any exceptions which were caught during the operation; otherwise, - /// - /// /// - /// The directory described by this object does not exist or could not be found. This - /// exception is not thrown if is . + /// The directory described by this object does not exist or could not be found. /// /// /// A target file is open or memory-mapped on a computer running Microsoft Windows NT. @@ -42,16 +28,10 @@ public static class DirectoryInfoExtensions /// -or- /// There is an open handle on the directory or on one of its files, and the operating system is Windows XP or earlier. /// This open handle can result from enumerating directories and files. - /// This exception is not thrown if is . /// - /// - /// The caller does not have the required permission. This exception is not thrown if is - /// . - /// - /// This directory or one of its children contain a read-only file. This - /// exception is not thrown if is . - /// - public static void Clear(this DirectoryInfo directory, bool throwOnError) + /// The caller does not have the required permission. + /// This directory or one of its children contain a read-only file. + public static void Clear(this DirectoryInfo directory) { #if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(directory); @@ -64,44 +44,17 @@ public static class DirectoryInfoExtensions if (!directory.Exists) { - if (throwOnError) - { - throw new DirectoryNotFoundException(); - } - - return; + throw new DirectoryNotFoundException(); } foreach (FileInfo file in directory.EnumerateFiles()) { - try - { - file.Delete(); - } - catch when (throwOnError) - { - throw; - } - catch - { - // do nothing - } + file.Delete(); } foreach (DirectoryInfo childDirectory in directory.EnumerateDirectories()) { - try - { - childDirectory.Delete(true); - } - catch when (throwOnError) - { - throw; - } - catch - { - // do nothing - } + childDirectory.Delete(true); } } }