PowerShell: List Files by File Name Pattern (grep file names)

By Xah Lee. Date: . Last updated: .

Filter File Names by Wildcard (-filter)

-filter parameter takes a Wildcards pattern to show only those files. Useful if you want to list files of a specific filename extension.

You cannot use the filter parameter for multiple extensions.

# list jpg files
dir -recurse -file -filter *.jpg
# list emacs backup files (file name ending in ~)
dir -recurse -file -filter *~

Filter File Name by Multiple File Extensions (-include / -exclude)

You can use -include or -exclude with Wildcards to filter out files by multiple file name extensions. e.g. -include *.jpg,*.png


dir -recurse -file -include *.jpg,*.jpeg
# or
dir -recurse -file -include "*.jpg","*.jpeg"


dir -recurse -file -exclude *.jpg,*.jpeg

Filter File Names by Regular Expression

The where-object cmdlet is useful to filter files by a boolean test of Regular Expression pattern match. [see Pipeline Commands] This is the most powerful, but not intuitive.

# list jpg files
dir -recurse -file | where { $_.name -iMatch "\.jpg|\.jpeg|\.jfif"}

Note: -iMatch ignore letter case. [see String Operators]


Practical How-To

list files

list dirs

on dir

on file

Windows config


PowerShell in Depth

Programing PowerShell

Value Types





Data Structure

Loop and Iteration



Profile and Script

Script Examples