Does a Folder contain a specific file?

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.


Posted Jul 31 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.