|
Answer» Hi ,
I have a requirement where i have to select LATEST file from a directory and RENAME it.
The sample files will be Epaccts20070427080147.XML .I should pick recent file and rename it to input.xml.
I'm using Microsoft Windows XP [Version 5.1.2600]
If the file already exists it should not rename.
Any help will be appreciated.
Thanks, So you want the most recent file based on what? Last modified, creation date?
If input.xml exists you don't want ANYTHING to happen but if it doesn't you want to grab the most recent xml document in the folder and rename it to input.xml?
Quote @ECHO off
if exist "input.xml" ( echo Input.xml already exists, will exit pause >nul exit )
:find set name= for /f "usebackq delims=" %%I in (`dir "*.xml" /b /o:-d`) do ( set name=%%~nxI goto rename )
:rename if "%name%"=="" ( echo xml not found, exiting pause >nul exit )
ren "%name%" "input.xml"
echo Done pause >nul
Somthin like that?
|