I’m writing a PowerShell script in which I need to get a list of files that have complementary .md5 files. For example, if I have a file name abc.txt I only want to add it to the list if there exists a file named abc.txt.md5 in the same directory.
This is my attempt, but it’s not working. I’m not sure why?
$DirectoryToScan = ".\SomePath"
$Files = Get-ChildItem $DirectoryToScan -Recurse |
Where-Object { !$_.PSIsContainer } |
Where-Object { $_.Name -notmatch ".*\.md5" } |
Where-Object { Test-Path "$($_.FullName).md5" }
It works fine without the last Where-Object clause.
What you had give does work for me, but you can try doing something like this: