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
Need help renaming large amounts of files
Moderator: DosItHelp
Re: Need help renaming large amounts of files
You could try something like that:
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
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
very good, thank you. Had to run the batch a few times for names with multiple "&" in it, but worked great.