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
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%
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

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%
Answered 04/04/2012 by: djfg4765
White Belt

Please log in to comment

Answers

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.
Answered 04/03/2012 by: dchristian
Red Belt

  • 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.
Please log in to comment
Answer this question or Comment on this question for clarity

Share