Batch File- Only Copy most recent file

Microsoft Windows xp professional w/serv...
July 1, 2010 at 16:53:03
Specs: Windows XP, 1.86 GB
Hello- First off...this is a great site and it has helped me quite a bit. I am in need of a batch file that finds the most recent file out on a shared drive...and then copies it to my desktop. I have similar requests for this on your site....and have tried using the code from several examples....but so far nothing has worked for me. This is my error: The filename, directory name, or volume label syntax is incorrect. The system cannot find the path specified.

Below is an example of code I am currently trying:

@echo off
setlocal
set srcDir= "O:\Historical_AOT\"
set destdir= "O:\Test\"
set lastmod=
pushd "%srcDir%"
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set lastmod=%%a
if "%lastmod%"=="" echo Could not locate files.&goto :eof
copy "%lastLog%" "%destDir%"
pause

Any thoughts/suggestions would be appreciated.

Thanks

Frank Sweeney


See More: Batch File- Only Copy most recent file

Report •

#1
July 1, 2010 at 17:18:30
This should be posted here for more help:

http://www.computing.net/forum/prog...


Report •

#2
July 1, 2010 at 23:42:23
copy "%lastLog%" "%destDir%"


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

M2


Report •

#3
October 7, 2010 at 10:14:17
Hello everybody.

I find this post very usefull. I was wondering if it is possible to apply an additional condition to this: can we narrow the search to a specific filename mask?

For instance, srcDir contains files named DATPxxxx; DTRPxxxxxxx; RTDxxxxxxx;
The purpose is to find the latest modified file on the folder, that matches the mask DTRP....

In what way would it be possible using this same Batch file?

Thks in advance.
Paulo (Portugal)


Report •

Related Solutions

#4
October 7, 2010 at 10:21:12
not tested

('dir /b /od DTRP*.* 2^>NUL')


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

M2


Report •

#5
October 22, 2010 at 03:21:06
thks a lot M2go !!

Report •

Ask Question