I want to get the physical path of given file name. For
EX: i have my project in drive E:\ and need to search the physical path of "x.txt" file which is resides in C drive.
I want to get the physical path of given file name. For
EX: i have my project in drive E:\ and need to search the physical path of "x.txt" file which is resides in C drive.
Yes.
var matchingFilePaths = Directory.EnumerateFiles(@"C:\")
.Where(filePath => filePath.EndsWith("x.txt"));
If you need to work with the file contents, you can start with using FileInfo
:
var fileInfo = new FileInfo("path\to\file.ext");
var fullPath = fileInfo.FullName;
Putting it together:
var matchingFiles = Directory.EnumerateFiles(@"C:\")
.Where(filePath => filePath.EndsWith("x.txt"))
.Select(filePath => new FileInfo(filePath).FullName);