Page 1 of 1

Batch routine to change file names

Posted: 22 May 2008 20:50
by NelsonS
I need some help creating a batch file to rename some 6k files.
The file names are seven numbers dot jpg.
NNNNNNN.jpg (b4)
I would like to change the first number only and swap it with 3 letters and a dash.
LLL-NNNNNN.jpg (after)
I would like to do that to all contents of a given directory until every file is modified in that format.

Thanks in advance for the assist.

Nelson

Posted: 25 May 2008 06:16
by jeb
Hi Nelson,

begin with this

Code: Select all

@echo off
setlocal enableextensions
setlocal enabledelayedexpansion

set srcPath=c:\temp\hund
set prefix=LLL-
echo %prefix%

for %%a in (%srcPath%\*.*) do (
   set oldName=%%~nxa
   set newName=%%~dpa%prefix%!oldName:~1!
   echo ren !oldName! !newName!
)


jeb

Batch

Posted: 11 Jun 2008 20:48
by NelsonS
thanks Jeb,

I'll try that.