-1

I want to find a file that has .pdf extension and I want to find with name too. For example I have filename = "Work.pdf". I want to write a method that could find with name. Is there any builtin method for this?

string fileName = "Work.pdf"
string[] files = System.IO.Directory.GetFiles("C:\Files", "*.pdf");
// string myWorkPdfFile = files.Where() //search the files with fileName
Huma Ali
  • 1,759
  • 7
  • 40
  • 66

1 Answers1

0

You can try to pass fileName value be second parameter.

string fileName = "Work.pdf";
string[] files = System.IO.Directory.GetFiles(@"C:\Files", fileName);
D-Shih
  • 44,943
  • 6
  • 31
  • 51
  • Shouldnt `fileName` not be `*Work.pdf` - or anything with a wildcard since your code is basically only searching for `C:\Files\Work.pdf` and this one only - so he could just simply do `var file = @"C:\Files\Work.pdf"` without "searching" it with `Directory.GetFiles()` – Rand Random Oct 03 '18 at 13:56