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
703 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 95

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 69

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

749 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