Link to home
Start Free TrialLog in
Avatar of Bob
BobFlag for United States of America

asked on

Copy the three newest files. This batch or script will run every day.

I need to copy the three newest files from a log directory to another. This process will repeat every day at a designated time so I would like to be able to batch this or script this so that it only pulls the three newest files. Can anyone help?
ASKER CERTIFIED SOLUTION
Avatar of sungenwang
sungenwang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob

ASKER

Works perfectly! Thank you very much.
here a batch .. no points
@echo off
 
set /a numDONE=0
for /f %%D in ('dir/b/a-d/o-d') do call :sub1 %%D
goto :eof
 
:sub1
 
if %numDONE%==3 goto :eof
echo copy %1 place
set /a numDONE+=1
goto :eof
:: DONE

Open in new window

You're welcome!
sew
Avatar of RobSampson
rpollick, although you've been registered on EE for some time, congratulations on receiving a perfectly accurate solution on your first post.  Nicely done sew, that's a great solution.

rpollick, you should now be able to accept the relevant comment as a solution, so the question can be closed.  Also note that in future, if you feel that one or comments contributed to your solution, you can accept multiple answers.

Regards,

Rob.