'Getting -Filter or -Include values from .txt file

I have a txt file with filenames (i.e 01234.tif) that I would like to use to filter a Get-ChildItem cmdlet. I did

$filenames = Get-Content filenames.txt

(also tried with | Out-String)

and then

Get-ChildItem . -Include $filenames | ForEach {if (!(Test-Path -Path ./jpeg/$_.Basename+".jpg")) {some imagemagick processing}}

but it does nothing. Funny part is that it works for excluding, since

Get-ChildItem . -Exclude $filenames > exclude.txt

writes the expected amount of lines. What am I missing here?

Get-Content filenames.txt | ForEach (path test) {imagemagick}

runs but copies all items, so either the path checking or Get-Content isn't working as expected.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source