Page 1 of 1

Need help renaming large amounts of files

Posted: 27 Mar 2010 19:27
by sxekjb
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

Re: Need help renaming large amounts of files

Posted: 28 Mar 2010 07:34
by aGerman
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

Re: Need help renaming large amounts of files

Posted: 28 Mar 2010 10:55
by sxekjb
very good, thank you. Had to run the batch a few times for names with multiple "&" in it, but worked great.