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
707 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
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…

739 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