Solved

I need a batch file that will locate the most recent file in a folder and copy only that file to anther folder.

Posted on 2011-03-05
3
711 Views
Last Modified: 2012-05-11
I need a batch file that will locate the most recent file in a folder and copy only that file to anther folder.
0
Comment
Question by:SteveIBS
[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
3 Comments
 
LVL 96

Accepted Solution

by:
Lee W, MVP earned 400 total points
ID: 35044570
I believe this should do the trick

@echo off
for /f "tokens=*" %%a in ('dir /b /od "c:\source\path"') do @set LastFile=%%a
copy "c:\source\path\%lastFile%" "c:\target\path"

Open in new window

0
 
LVL 11

Expert Comment

by:marek1712
ID: 35046401
Or PowerShell oneliner...
 
$var = Get-ChildItem SOURCE | Sort-Object CreationTime -Descending; Copy-Item $var[0] DESTINATION

Open in new window

CreationTime - date/time when the file was created. You can change it to LastWriteTime if you new most recently written file.
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 100 total points
ID: 35047242
Or
@echo off
set LastFile=
for /f "tokens=*" %%F in ('dir /b /o:-d "c:\source\path"') do if not defined LastFile set LastFile=%%F
copy "c:\source\path\%LastFile%" "c:\target\path"

Open in new window

0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

691 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