# Robocopy - how to copy the NEWEST file in catalog?

I want to copy one file that is the newest in whole catalog. How to do it using robocopy? I know /xo and /xn options but it doesn't do what I need.

-

## migrated from stackoverflow.comMar 28 '13 at 0:22

This question came from our site for professional and enthusiast programmers.

Interesting idea, does it have to be done with RoboCopy?

I would try something like this using PowerShell:

(Get-ChildItem -Path Path:\to\files\here -Recurse -File | Sort-Object -Descending LastWriteTime)[0] | Copy-Item -Destination Path:\to\destination\here -Force


So to do that in robocopy, you can just use the (Get-ChildItem -Path Path:\to\files\here -Recurse -File | Sort-Object -Descending LastWriteTime)[0] part and set it to a variable, and pass it in to a RoboCopy line.

Robocopy is good for mirroring and transferring lots of files/directories, but it doesn't do delta style copies so it might not be the best for this situation. I also took a guess you meant last file written to, you could use LastAccessTime if that fits better.

-