Add File.TryDelete and Directory.TryDelete returning bool#20
Merged
Conversation
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/d52ecff8-cf72-4e4b-83d7-0bc000aa04dd Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/d52ecff8-cf72-4e4b-83d7-0bc000aa04dd Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
Tyrrrz
April 14, 2026 15:03
View session
Tyrrrz
approved these changes
Apr 14, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds TryDelete extension methods to simplify deleting files/directories by swallowing exceptions and returning a bool success indicator.
Changes:
- Add
File.TryDelete(string) -> boolwrapper aroundFile.Delete. - Add
Directory.TryDelete(string, bool recursive = false) -> boolwrapper aroundDirectory.Delete. - Add unit tests covering success, non-existent targets, and recursive/non-recursive directory deletion behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| PowerKit/Extensions/FileExtensions.cs | Adds File.TryDelete extension returning bool. |
| PowerKit/Extensions/DirectoryExtensions.cs | Introduces Directory.TryDelete extension returning bool. |
| PowerKit.Tests/FileExtensionsTests.cs | Adds tests for File.TryDelete (existing + missing file). |
| PowerKit.Tests/DirectoryExtensionsTests.cs | Adds tests for Directory.TryDelete (existing, missing, non-empty, recursive). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
TryDeleteextension methods onFileandDirectorythat swallow exceptions and return aboolindicating success.Changes
FileExtensions—File.TryDelete(string path) → bool: wrapsFile.Delete; returnstrueeven for non-existent paths (consistent with BCL behavior whereFile.Deleteis a no-op on missing files)DirectoryExtensions(new file) —Directory.TryDelete(string path, bool recursive = false) → bool: wrapsDirectory.Delete; returnsfalsefor non-existent directories or non-empty directories whenrecursiveisfalseUsage