Fearghal
Fearghal

Reputation: 11447

Ren windows cmd batch file

Is there a way to rename the oldest file in a directory to 'file_oldest'?
I am not sure how to combine date with ren cmd

Upvotes: 0

Views: 830

Answers (1)

Matt Williamson
Matt Williamson

Reputation: 7117

Here you go. It's a bit trickier for a UNC path.

@echo off
setlocal
set share=\\server\xxxx\xxxx\xxxx\xxxxx
for /f "tokens=*" %%a in ('dir "%share%" /b /a-d /o-d') do (set oldest="%%a")
ren "%share%\%oldest%" file_oldest

Upvotes: 1

Related Questions