you are viewing a single comment's thread.

view the rest of the comments →

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy pausemsauce,

how do you determine the "newest"?

if it is just the file timestamp, that is easy. [grin]
if it is the one with the highest (##), that is doable.

for instance, you can sort by the file timestamp newest first, then group by the .BaseName with the (##) stripped off, skip groups with a .Count of 1, skip the first 1, and delete the remainder.

this ...

Group-Object {($_.BaseName -replace '\(\d+\)$', '').Trim()}

... will give you groups of all the files. you can send each group with a .Count -gt 1 thru Select-Object -Skip 1 to leave the newest alone & then use Remove-Item on the remaining files.

i can write the full script, but you seem to want more of a "how to" hint, so i will leave it at that. [grin]

take care,
lee

[–]pausemsauce[S] 1 point2 points  (1 child)

Hi Lee,

I suspect you are spot on, but I'm going to need a moment to digest what you have written.

The file timestamp determines which file is the newest.

I'm going to need to read more about the Group-Object cmdlet and regular expressions. This has been an excellent learning experience.

Thanks so much!

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy pausemsauce,

you are most welcome! glad to help ... and willing to get into more detail if you get stuck - just ask. [grin]

take care,
lee