Does a Folder contain a specific file?

by Jul 31, 2009

Test-Path supports wildcards so if you'd like to know whether there are any PowerShell script files located in your home folder, try this:

Test-Path $home*.ps1

To get the actual number of PowerShell scripts, use Get-Childitem and count the result:

@(Dir $home*.ps1).Count

Note the @() converts any result into an array so even if there is only one file or none, the result will be an array so you can safely query its Count property.