Problem:
get the latest file in the folder with batch command, in my case after getting the latest file. i will move it to other directory

Solution:
copy and paste this code, change it according to your need

@echo off
setlocal
:source directory
set srcDir= your source directory
:destination directory
set destdir=your destination directory
set lastmod=
pushd “%srcDir%”
for /f “tokens=*” %%a in (‘dir /b /od 2^>NUL’) do set lastmod=%%a
if “%lastmod%”==”" echo Could not locate files.&goto :eof
:copy
copy “%lastmod%” “%destdir%”
:delete
del “%lastmod%”

enjoy :)