Find the first file that matches a pattern using PowerShell

Viewed 53706

I would like to select any one ".xls" file in a directory. The problem is the dir command can return different types.

gci *.xls

will return

  • object[] if there is more than one file
  • FileInfo if there is exactly one file
  • null if there are no files

I can deal with null, but how do I just select the "first" file?

1 Answers
Related