Question : Batch Command to Rename Most Recently Created File in a Folder

I need batch file commands to rename the most recent file in a directory.  The directory may contain mutiple files and the names will vary, but I only want to rename the most recently created file to a specific name like "MostRecentFile.txt".  The directory resides on a Win 2K server.

Answer : Batch Command to Rename Most Recently Created File in a Folder

Try this:

@echo off
setlocal
Set MyFolder=T:\he\directory
for /f "delims=" %%a in ('dir /b /o:d /a:-d "%MyFolder%"') do set LatestFile=%%a
echo Latest File in %MyFolder%: %LatestFile%
ren "%MyFolder%\%LatestFile%" "MostRecentFile.txt"
Random Solutions  
 
programming4us programming4us