Move most recent .txt file to a new location

May 12, 2011 at 02:50:31
Specs: Windows XP
I wish to copy the most recent .txt file from one location to another

the files are datestamped i.e. 20110511_dailydata.txt

there are many different .txt files saved down each day - but I am only interested in _dailydata.txt

I wish to select the 'newest' _dailydata.txt file and copy it to a new folder location


thanks


See More: Move most recent .txt file to a new location

Report •

#1
May 12, 2011 at 06:48:02
@echo off & setlocal
set dircmd=/O-D
cd Source_Directory
for %%j in (????????_dailydata.txt) do (copy %%j "Target_Directory" & goto :EOF)


Report •

#2
May 12, 2011 at 07:55:16
thank you

I also managed to get it working with this code:

@echo off 
set sourcedir=C:\SOURCE
set destdir=C:\COPY
for /f "tokens=1 delims=" %%a in ('dir /b /o:d "%sourcedir%\*dailydata.txt"') do set newest=%%a 
copy %sourcedir%\%newest% %destdir%\dailydata.txt


Report •
Related Solutions


Ask Question