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
666 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
3 Comments
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 400 total points
Comment Utility
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
Comment Utility
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 68

Assisted Solution

by:Qlemo
Qlemo earned 100 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now