Need help renaming large amounts of files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sxekjb
Posts: 16
Joined: 07 Nov 2009 19:13

Need help renaming large amounts of files

#1 Post by sxekjb » 27 Mar 2010 19:27

I need to rename files that have "&" in the name and replace with "and". I'm using dir /s /a | find /i "&" to find all of the file names.

Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help renaming large amounts of files

#2 Post by aGerman » 28 Mar 2010 07:34

You could try something like that:

Code: Select all

@echo off &setlocal
for /f "delims=" %%a in ('dir /b /s^|findstr /c:"&"') do set "fullname=%%a" &set "name=%%~nxa" &call :process
pause
goto :eof

:process
set "newname=%name:&=and%"
ren "%fullname%" "%newname%"
goto :eof


Don't forget all the quotes. Otherwise some of the ampersands will be missinterpreted.

<EDIT Sorry, I've not observed the syntax of ren. Fixed now. />

Regards
aGerman

sxekjb
Posts: 16
Joined: 07 Nov 2009 19:13

Re: Need help renaming large amounts of files

#3 Post by sxekjb » 28 Mar 2010 10:55

very good, thank you. Had to run the batch a few times for names with multiple "&" in it, but worked great.

Post Reply