The Multifunctioning DBA

Aug 18 2009   5:47PM GMT

Find how many files of any extension are in a folder



Posted by: Colin Smith
One Liners, Powershell, Powershell Tips, Scripting, System Administration

Recently I needed to find out if I had any files of a certain extension in a particular folder and if so how many. With Powershell this is no problem at all.

Say I was looking for a count of .ps1 files in the directory.

@(Dir Directorypath\*.ps1).Count

The @() makes the result go into an array object. This way no matter what you will get an accurate count without having to do a for loop on that directory.

Comment on this Post

Leave a comment: