Hello chriseldorado,
Welcome to Microsoft Q&A forum.
As I understand, you want to copy only the latest version of the file copied to the destination folder and also strip the UTC part of the name, am I correct?
The versions are encoded by the file name, not just modified date. So Xcopy and Robocopy are unable to do this. You will need to use PowerShell for this. I will assume that the destination folder already exists for this scenario.
- Type PowerShell in the search bar and select "Run as administrator"
- Type these commands one by one and press Enter after each.
- $src = "E:\complete orig file history\Documents\Memoirs by Helen"
- $dst = "C:\Users\user\Documents\Memoirs by Helen"
- Paste this script and press Enter. Get-ChildItem -Path $src -File | ForEach-Object { if ($.Name -match '^(.*?) ((\d{4}\d{2}\d{2} \d{2}\d{2}_\d{2} UTC))(..*)?$') { [PSCustomObject]@{ BaseName = $matches[1] Timestamp = [datetime]::ParseExact( $matches[2], 'yyyy_MM_dd HH_mm_ss UTC', $null ) Extension = $matches[3] File = $_ } } } | Group-Object { $.BaseName + $.Extension } | ForEach-Object { $latest = $_.Group | Sort-Object Timestamp | Select-Object -Last 1 Copy-Item ` -Path $latest.File.FullName ` -Destination (Join-Path $dst ($latest.BaseName + $latest.Extension)) }
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.