Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DOS Compare File Name

Posted on 2013-01-08
2
Medium Priority
?
373 Views
Last Modified: 2013-04-26
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
0
Comment
Question by:youpa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 38755914
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.
0
 
LVL 58

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 38756767
Here's a slightly different variation, that sorts the matching files in reverse order so that once it copies the latest one it leaves the loop. Small gain in performance, and if there really are just two files doesn't matter a lot, but wanted to share it just as a slight alternate approach.

@echo off
setlocal

set BaseDir=C:\Source
set DestDir=C:\Target
set Filename=PDF Flash Color Daily Sales Flash*.pdf

for /F "tokens=*" %%F in ('dir /B /O-N "%BaseDir%\%Filename%"') do (
  copy "%BaseDir%\%%~F" "%DestDir%"
  goto :CopyDone
)
:CopyDone

Open in new window

~bp
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question