Created
June 10, 2023 14:32
-
-
Save 5cover/0983a6db6b07c5114cbf491e1aa3631f to your computer and use it in GitHub Desktop.
Check if path is in directory.
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
public static bool IsInDirectory(this FileInfo file, DirectoryInfo directory) => file.Directory?.IsInDirectory(directory) ?? false; | |
[SuppressMessage("Globalization", "CA1309", Justification = "Path comparison")] | |
public static bool IsInDirectory(this DirectoryInfo path, DirectoryInfo directory) | |
=> path.Parent != null && (path.Parent.FullName.Equals(directory.FullName, StringComparison.InvariantCultureIgnoreCase) || path.Parent.IsInDirectory(directory)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment