Batch file with latest date in file name

Dell /
November 18, 2009 at 12:54:39
Specs: Windows XP
Hello,

If I wanted to create a batch file, which I could
run on a daily basis, and where the only
reliable run date is contained in the name of
the file, how could this happen?

ie. In a given folder, there are files created
daily with the date in it. For example:

01.11.09-ABC.xls
02.11.09-ABC.xls
03.11.09-ABC.xls
04.11.09-ABC.xls
05.11.09-ABC.xls

These files are created daily, and ideally what
I'm looking at doing is creating a new file
called "DailyABCReport.xls" that will be over-
written each day with the latest report, and
scheduled to run and update automatically.

The new report would be copied as and saved
in:

C:\web\DailyABCReport.xls

This file would be linked with a web-based
interface.

Thanks!


See More: Batch file with latest date in file name

Report •


#1
November 18, 2009 at 13:56:22
Not quite with you on the linking, but this will get the copy done.

=============================
@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/o-d *-ABC.xls') do (
copy "%%a" C:\web\DailyABCReport.xls
goto :eof
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
November 19, 2009 at 06:38:31
Mechanix2Go, thank you so much! This is wonderful!

Now supposing we had a folder created for each month?

For example:

Sep 09
Oct 09
Nov 09

And within the corresponding folder, they keep the most
updated spreadsheet, as in above?

Is there a way for this function to search all folders in the
directory?


Report •

#3
November 20, 2009 at 04:56:37
So are you trying to get the latest file for each month?


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
December 1, 2009 at 05:56:43
Not from each month, but just the VERY latest file in the very
latest folder.

So for example:

If there is a folder that has the following folders:

Sep 09
Oct 09
Nov 09
Dec 09

And in each of these folders are daily excel files, I want it to
find the most recent file and the corresponding folder it
belongs to.


Report •

#5
December 2, 2009 at 01:06:55
Run this and post a few lines of the output:

============================
@echo off > newfile & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in ('dir/b *.xls') do (
echo %%~Ta %%a
)


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question