Just tossing out guesses, but what if you write *.txt and could it be that the trim statement should be ([regex]::Replace($_.FullName, $filepathRegex, '$1')).Trim() in order to trim the whole thing? Other than that, without a clue as to what is in your variables, that's all I got.
|