Get only file with given extension in directory
I would use Get-ChildItem -Filter
and Select-Object -First
:
$filepath = Get-ChildItem -Path $dir -Filter *.xyz |Select -First 1
I would recommend using Get-ChildItem
's -include
parameter:
Get-ChildItem $dir -include *.xyz