/build/static/layout/Breadcrumb_cap_w.png

Copy newest source file

Hi,

Looking for a Windows command line to copy a log file from C:\temp folder to a destination folder where I store my log files.

I have looked at robocopy and xcopy and I cannot find the switches to take the latest or newest file (using wildcards as logfiles keep same name but append new number - name*.txt) to another folder. I know robocopy has /maxage and xcopy has /d but these compare to the destination timestamps not the latest log file in source. Any help would be appreciated. thanks

0 Comments   [ + ] Show comments

Answers (2)

Answer Summary:
Here is the solution I went with... SET temp=%USERPROFILE%\AppData\Local\Temp SET logfiledir=%windir%\logs FOR /F "delims=|" %%I IN ('DIR "%temp%\_*.txt" /B /O:D') DO SET NewestFile=%%I copy "%temp%\%NewestFile%" "%logfiledir%
Posted by: djfg4765 12 years ago
White Belt
2
Here is the solution I went with...

SET temp=%USERPROFILE%\AppData\Local\Temp
SET logfiledir=%windir%\logs

FOR /F "delims=|" %%I IN ('DIR "%temp%\_*.txt" /B /O:D') DO SET NewestFile=%%I
copy "%temp%\%NewestFile%" "%logfiledir%

Comments:
Posted by: dchristian 12 years ago
Red Belt
1
Correct me if I'm wrong but doesn't robocopy move only files that have changed? Couldn't you copy everything? After the initial sync, robocopy would only be taking the "newest" files.

Comments:
  • The problem is the logfile in temp folder changes name each time its created. Only difference being a new number is added to log file name. - djfg4765 12 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Link

Related Links

Post

Related Posts

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ