TetraFlash
TetraFlash

Reputation: 327

Find filenames with certain characters

This is my first post :D ... I have never needed to post since all my answers have always been already answered. I look but didn't find anything to answer this.

I have a directory ( call it temp ) in C:\ and I need to find all files in it (recursively) that contain ANY of these characters ~!@#$%^&*()+., OR a space. I then need them listed with their location, I dont care about the date or permissions (infact I would prefer them removed)

I also need the option to filter *.htm

I tried playing with GCI and Select-String, but select-string kept reading the content of my files and I am not very good with regular expressions.

Thanks in advance for the help, I know the people on here know their stuff (4 years before I had to post a question :D)

Upvotes: 1

Views: 141

Answers (1)

Andrey Marchuk
Andrey Marchuk

Reputation: 13483

Try this:

$files = Get-ChildItem "c:\PST\"
$files = ($files | Where-Object {$_.BaseName.IndexOfAny("~!@#$%^&*()+., ".ToCharArray()) -ne -1})
$files

Upvotes: 1

Related Questions