Created
December 18, 2019 20:20
-
-
Save searope/dcdd0b7eac2ebbba7a8883d9dc77d8ec to your computer and use it in GitHub Desktop.
Finds file or folder in parents folder
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 string FindUpperFileOrFolder(string name, DirectoryInfo dir = null) | |
| { | |
| dir = dir ?? new DirectoryInfo(Directory.GetCurrentDirectory()); | |
| var dirInfo = dir.GetDirectories(name).FirstOrDefault(); | |
| var fileInfo = dir.GetFiles(name).FirstOrDefault(); | |
| if (fileInfo == null && dirInfo == null) | |
| { | |
| return FindUpperFileOrFolder(name, dir.Parent); | |
| } | |
| return fileInfo != null ? fileInfo.FullName : dirInfo.FullName; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment