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
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%
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%
Please log in to answer
Posted by:
djfg4765
12 years ago
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%
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:
-
Nice! - dchristian 12 years ago
Posted by:
dchristian
12 years ago
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