Windows 'dir' command: sort files by date when '/s' is specified
问题 Goal: I want to copy the latest file with a certain extension from a "source directory" to a "destination directory" using a batch file. The latest file may be under several sub-directories within the source directory. This question/answer is exactly what I want, however it does not seem to sort when the /s option is specified (as this comment would suggest): FOR /F "delims=|" %%I IN ('DIR "K:\path\tp\source\dir\*.ext" /B /S /O:D') DO SET NewestFile=%%I copy "%NewestFile%" "C:\path\to