Rename files from oldest to newest

December 3, 2009 at 17:49:20
Specs: Windows XP
Directory can contain between 1 and 7 files.
I need to rename oldest by creation date filexxx.txt to file1.txt,
next oldest filexxxx.txt to file2.txt
the most recent filexxxx.txt to file7.txt

Would anyone have any ideas?

Thank you

See More: Rename files from oldest to newest

Report •

December 3, 2009 at 19:29:02
@echo off
setlocal enabledelayedexpansion
set /a ct=0
for /f "tokens=* delims-" %%a in ('dir file*.txt /a:-d /o:d') do (
set /a ct+=1
set new=%%a
:"4" is based on "file", if length is diff. substitute actual length
set new=!new:~0,4!
:foll two lines are for testing. examine temp.bat to see if...
echo ren %%a new!ct!
echo ren %%a new!ct! >> temp.bat
:ren %%a new!ct!)

might do it.

Report •

December 3, 2009 at 19:31:58
@echo off & setLocal EnableDELAYedExpansion

set N=
for /f "tokens=* delims= " %%a in ('dir/b/od file????.txt') do (
set /a N+=1
ren %%a file!N!.txt

Helping others achieve escape felicity


Report •

December 4, 2009 at 08:14:45
I'm very glad I asked. Thank you very much, guys. It works very well for me. :)

Report •

Related Solutions

Ask Question