Use
System.IO.Directory.GetFiles
.
You need to be extra careful, see the discussion here:
Directory.Get.Files search pattern problem[
^].
The ultimately correct answer was given my Abhishek Sur; see also my answers and discussion. In your case it should be:
var files =
System.IO.Directory.GetFiles(
directory,
"*.rtf").Where(
item =>
item.Where(item => item.ToLower().EndsWith(".rtf"));
If you simply use
GetFiles
without
Where
, it might also return all the files with names like *.rtfa, *.rtfab, that is, *.rtf?, *.rtf??, and so on.
—SA