I’m having 2 files named the same way but having the date stamp and second stamp at the end ( YYYY-MM-DD HH-MM-SS)
Exemple : PDF Flash Color Daily Sales Flash2013-01-08 08.32.41.326.pdf
PDF Flash Color Daily Sales Flash2013-01-08 08.45.41.326.pdf
And I would like to ensure to copy only the most resent one. How can I do that ?
This need to be done in batch.
Thanks a lot
Microsoft DOSShell ScriptingScripting Languages
Last Comment
Bill Prew
8/22/2022 - Mon
oBdA
Since you have a sensible naming convention (that is, yyyymmdd instead of mmddyyyy), you can just use a regular directory sorting and pick the last one. The script below is in test mode and will only display the copy command; remove the uppercase ECHO in front of "copy" to run it for real:
@echo offsetlocalset SourceFolder=C:\Sourceset TargetFolder=C:\Targetset Prefix=PDF Flash Color Daily Sales Flashfor /f "delims=" %%a in ('dir /b /o:n "%SourceFolder%\%Prefix%*.pdf"') do set LatestFile=%%aecho Latest file: %LatestFile%ECHO copy "%SourceFolder%\%LatestFile%" "%TargetFolder%"
Open in new window
If the actual time stamps of the files are correct, you could use those, too, by changing "/o:n" to "/o:d" in line 6.