Skip to content

Add Directory.CreateForFile extension method#72

Merged
Tyrrrz merged 3 commits intoprimefrom
copilot/add-directory-extension-for-file-path
Apr 19, 2026
Merged

Add Directory.CreateForFile extension method#72
Tyrrrz merged 3 commits intoprimefrom
copilot/add-directory-extension-for-file-path

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

Adds a static extension method on Directory that creates the directory tree needed for a given file path.

Changes

  • DirectoryExtensions.cs — new Directory.CreateForFile(string filePath) method; extracts the directory component via Path.GetDirectoryName and delegates to Directory.CreateDirectory, creating all intermediate directories. No-ops if the path has no directory component.
  • DirectoryExtensionsTests.cs — two new tests covering a flat path and a deeply nested path.

Usage

// Ensures /some/nested/dir/ exists before writing
Directory.CreateForFile("/some/nested/dir/file.txt");
File.WriteAllText("/some/nested/dir/file.txt", content);

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/1af636ec-a6c0-4884-91e3-faa6ff0856be

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 19, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 19, 2026 10:24
Copilot AI review requested due to automatic review settings April 19, 2026 10:24
Comment thread PowerKit.Tests/Extensions/DirectoryExtensionsTests.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Directory.CreateForFile(string filePath) extension to ensure the parent directory tree exists for a given file path, aligning with PowerKit’s IO helper extensions and enabling safer “create dirs then write file” workflows.

Changes:

  • Added Directory.CreateForFile(string filePath) that creates the directory component of a file path (no-op if none).
  • Added tests intended to cover flat and nested file paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
PowerKit/Extensions/DirectoryExtensions.cs Introduces CreateForFile() extension that derives the directory via Path.GetDirectoryName() and creates it.
PowerKit.Tests/Extensions/DirectoryExtensionsTests.cs Adds tests for CreateForFile() behavior (currently one test doesn’t validate the intended behavior).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit.Tests/Extensions/DirectoryExtensionsTests.cs
Comment thread PowerKit.Tests/Extensions/DirectoryExtensionsTests.cs
Copilot AI requested a review from Tyrrrz April 19, 2026 10:27
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.88%. Comparing base (45628b8) to head (18be28c).
⚠️ Report is 1 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #72      +/-   ##
==========================================
+ Coverage   93.85%   93.88%   +0.02%     
==========================================
  Files         128      128              
  Lines        2524     2534      +10     
  Branches      200      201       +1     
==========================================
+ Hits         2369     2379      +10     
  Misses        112      112              
  Partials       43       43              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants