I have a file path (it is a virtual file system path) and I want to find files with a name "test.txt" from parent dir. to its root dir/
string test = "test.txt" Let say I have a path : root/dir1/dir2/dir3/dir4/file.cs
Now, if I do
string parentDirectoryName = Path.GetDirectoryName(file); //Here I get dir4
string filePath = Directory.GetFiles(parentDirectoryName, test ).FirstOrDefault(); //I get the path of the text.txt if it is present or i get null.
But now, I want to go until root (and see if there is any file named test.txt) and if yes, get the path of all those files.
O/P should be List<string>
with all file paths from current dir. to root dir. for a file named "test.txt"
How to do that ?