Avatar of youpa
youpa

asked on 

DOS Compare File Name

Hello,

Can someone help me,  

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

Avatar of undefined
Last Comment
Bill Prew
Avatar of oBdA
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 off
setlocal
set SourceFolder=C:\Source
set TargetFolder=C:\Target
set Prefix=PDF Flash Color Daily Sales Flash
for /f "delims=" %%a in ('dir /b /o:n "%SourceFolder%\%Prefix%*.pdf"') do set LatestFile=%%a
echo 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.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Scripting Languages
Scripting Languages

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.

30K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo