Link to home
Start Free TrialLog in
Avatar of PushCode
PushCode

asked on

renaming files but exclude newest

Wondering if it's possible, and if so how, to exclude the newest or most recently created/modified (shouldn't matter which) file when renaming all files in a given directory. If there happen to be four files in a directory, I only need to rename the three oldest files, leaving the most recent file as is.
Right now I'm using the following code to rename files:

ren \\prodweb01\logfiles\W3SVC1\ %%f in (ex*.log) do rename "%%~ff" *.prodweb01.log

Can this be modified to accomplish what I need?

I was thinking something like this might work, but it isn't. Is this even close?
It is returning %FirstFile% correctly....

@echo off
if '%2==' for /f %%a in ('dir C:\test\prodweb01\logfiles\W3SVC1\ %1 /b/o-d') do %0 %1. %%a
if not '%2==' set FirstFile=%2
if not %FirstFile% @for /r c:\test\prodweb01\logfiles\W3SVC1\ %%f in (ex*.log) do rename "%%~ff" *.prodweb01.log
ASKER CERTIFIED SOLUTION
Avatar of Bsmack
Bsmack

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial