Hi Salka, Milan
You can handle this with PowerShell. The idea is to group files by their "NameX" prefix, sort them by the timestamp in the filename, keep the newest one in place, and move the rest into a _backup folder. Here’s a quick script outline you can try:
$dir = "C:\Your\Directory\Path"
$backup = Join-Path $dir "_backup"
if (!(Test-Path $backup)) { New-Item -ItemType Directory -Path $backup }
Get-ChildItem $dir -Filter *.pdf | ForEach-Object {
$prefix = ($_ -split "_")[0]
[PSCustomObject]@{
Prefix = $prefix
File = $_
Date = ($_ -split "_")[1].Split(".")[0]
}
} | Group-Object Prefix | ForEach-Object {
$sorted = $_.Group | Sort-Object Date
$sorted[0..($sorted.Count-2)] | ForEach-Object {
Move-Item $_.File.FullName $backup
}
}
This way, for each prefix (like Name1, Name2, etc.), only the newest file stays in the main directory, and all older ones get moved to _backup. You can tweak the path and backup folder name as needed.
Give it a spin it should match the example you gave. And if this does the trick for you, don’t forget to hit **“**accept answer” so we know it helped!