简体   繁体   中英

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)

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM