Skip to content

Conversation

@cnaples79
Copy link

Summary

  • Fixed AbsolutePath.Exists() to check for both file and directory existence
  • Added explicit ExistsFile() method for file-only checks
  • Kept existing ExistsDirectory() method unchanged

Changes Made

Modified TruePath.SystemIo/PathIo.cs:

  • Changed Exists() implementation from File.Exists(path.Value) to File.Exists(path.Value) || Directory.Exists(path.Value)
  • Added new ExistsFile() method that checks only for file existence: File.Exists(path.Value)
  • Updated XML documentation for Exists() to reflect that it now checks for both files and directories

Problem Solved

Previously, calling folder.Exists() on a directory path would return false even if the directory existed, because the method only used File.Exists(). This broke code that needed to check if a path (file or directory) exists before performing operations like deletion.

With this fix:

  • Exists() returns true for any existing filesystem entity (file or directory)
  • ExistsFile() explicitly checks for files only
  • ExistsDirectory() explicitly checks for directories only

Fixes #171

Previously, AbsolutePath.Exists() only checked for file existence using
File.Exists(), which returned false for directories. This caused issues
when checking if a directory path exists.

Changes:
- Modified Exists() to check for both files and directories
  (File.Exists() || Directory.Exists())
- Added explicit ExistsFile() method for checking file existence only
- Kept ExistsDirectory() unchanged for directory-specific checks

This allows Exists() to correctly return true for any filesystem entity
(file or directory), while still providing explicit methods for
type-specific existence checks.

Fixes ForNeVeR#171
@ForNeVeR ForNeVeR self-assigned this Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AbsolutePath.Exists should return true if the entity is a directory

2 participants