How to get the name of most recently file in specific directory?

53 views Asked by At

I try to get the most recently name-file in specific directory, with dir command:

dir /O:D|tail -3 |head -1

but I got this line:

11/23/2014  01:18 PM               393 2.32.5100-results.json

thanks

1

There are 1 answers

0
MC ND On BEST ANSWER
dir /b /a-d /o-d | head -1 

And just for a native windows alternative

dir /b /a-d /o-d | cmd /v /c "set/p.=&&echo(!.!"

In both cases, execute a dir command, in bare format, without folders in date descending order and pipe the information into a

  • head command that will retrieve the only the first line (the newest file)

or

  • a cmd instance that will retrieve the first line (the newest file) and echo it to console