get the latest file with batch command

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 :)

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>