var GetFileByFileName = Directory.GetFiles(SourceFilePath)
.Select(x => new FileInfo(x))
.Where(x => x.Name==SourceFileName)
.Take(1)
.ToArray();
This is my code for fetch file by Specified File name.Here i am using array . In here SOURCEFILENAME is an string variable which having the file name.but it is not working.i could get all files from directory.but i need only one file from directory based on the SOURCEFILENAME.? Please help me..Thank You. .
if you want to use the way what you currently used then you have implement be in below mentioned way
var GetFileByFileName = Directory.GetFiles(@"D:\Re\reactdemo")
.Select(x => new FileInfo(x))
.Where(x => x.Name == "package.json")
.Take(1)
.ToArray();
check your SourcePath should look like what I have hard coded in code and your source file should be with extension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With