Mass rename of file extensions recursively (windows batch) Mass rename of file extensions recursively (windows batch) windows windows

Mass rename of file extensions recursively (windows batch)


On Windows 7, the following one-line command works for me, to rename all files, recursively, in *.js to *.txt:

FOR /R %x IN (*.js) DO ren "%x" *.txt


for /r startdir %%i in (*.inp) do ECHO ren "%%i" "%%~ni.txt"

should work for you. Replace startdir with your starting directoryname and when you've checked this works to your satisfaction, remove the echo before the ren to actually do the rename.


For the downvoters: executing a batch file differs from excuting from the command prompt in that each %%x where x is the metavariable (loop-control variable) needs to be reduced to %, so

for /r startdir %i in (*.inp) do ECHO ren "%i" "%~ni.txt"

should work if you execute this from the prompt. Please read the note about echo.


John Smith's answer is excellent, and it works. But to be completely clear (I had to re-read magoo's notes to figure out the correct syntax), here is exactly what you need to do...

BATCH FILE:FOR /R %%x IN (*.js) DO ren "%%x" *.txtCOMMAND LINE:FOR /R %x IN (*.js) DO ren "%x" *.txt

Up vote their responses, I am but a lowly formater...