Copy and rename mmost recent file

July 9, 2009 at 11:11:04
Specs: Windows XP
Hi,
I'm a newbie at batch file and can use some help. I'm trying to create a batch file that would copy the most recent file in a network directory to another network directory and rename the file.

The source network drive (K:\Institutional$\Instit\IDM\2009 Daily Historical - PDF) contains a series of PDF files:
GADaily 07 01 2009 II.pdf,
GADaily 07 02 2009 II.pdf,
GADaily 07 03 2009 II.pdf,
GADaily 07 04 2009 II.pdf, etc...
New files are added daily. I would like to copy the most recent file in this directory to another network drive (K:\Institutional\Instit\SalesVision) and rename it to "GADailyTerritoryChannel.pdf" and overwrite the previous "GADailyTerritoryChannel.pdf" file.

Any help is greatly appreciated. I'm running this on WINXP Professional.


See More: Copy and rename mmost recent file

Report •


#1
July 9, 2009 at 12:20:17
@echo off & setLocal enableDELAYedexpansion

set /p src=source ?:
set /p dest=dest ?:

pushd !src!

for /f "tokens=* delims= " %%a in ('dir/b/a-d/o-d *.pdf') do (
set latest=%%a
goto :OK
)

:OK
copy "!latest!" !dest!\GADailyTerritoryChannel.pdf > nul


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 9, 2009 at 13:41:16
Thank you very much for your help Mechanix2Go. This is what I put into the bat file:

@echo off & setLocal enableDELAYedexpansion

set /p src=K:\Institutional\Instit\IDM\2009 Daily Historical - PDF
set /p dest=K:\Institutional\Instit\SalesVision

pushd !src!

for /f "tokens=* delims= " %%a in ('dir/b/a-d/o-d *.pdf') do (
set latest=%%a
goto :OK
)

:OK
copy "!latest!" !dest!\GADailyTerritoryChannel.pdf > nul


When I run it the command window just stop at K:\Institutional\Instit\IDM\2009 Daily Historical - PDF

What am I doing wrong?


Report •

#3
July 9, 2009 at 15:25:27
With the set /p it waits for user input.

So just edit out the /p and it will set the src and dest and go on it's way.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
July 9, 2009 at 15:48:20
Thank you for all your help Mechanix2Go

Report •


Ask Question