My requirement is to find a latest file name in a folder based on the last modified date. I need a command in single line. I am executing below command.
@echo off && (for /f "tokens=*" %a in ('dir /b/a-d/od/t:w *.*') do set newestfile=%a) && @echo on && echo %newestfile%
this is giving me correct result but the only issues that if I modify another file...then also it shows me previous filename. I have read that local variable doesn't get reset that's why it shows old/previous file.
I have written logic in batch script. that's working as expected but in command line its giving me weird result.