get the latest file with batch command

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

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

@echo off
: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 “%lastmod%” “%destdir%”
del “%lastmod%”

enjoy :)

This entry was posted in batch command and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>