I have several thousand files of different revisions in a folder.
ACZ002-0.p
ACZ002-1.p
ACZ002-2.p
ACZ051-0.p
ACZ051-1.p
...
The revision is always the last digit before the dot. I need to preserve only the files with the latest revision, but I don't know how to proceed with my code.
$path = "E:\Export\"
$filter = [regex] "[A-Z]{3}[0-9]{3}\-[0-9]{1,2}\.(p)"
$files = Get-ChildItem -Path $path -Recurse | Where-Object {($_.Name -match $filter)}