I have numerous files in a very complex directory structure, and for reasons not worth discussing I need to rename all files with the extension of ".inp" to have ".TXT" extensions. There are numerous other files with other extensions that I do not want to be touched, and I want to do it recursively down at least 5 levels.
So far I have:
for /d %%x in (*) do pushd %%x & Ren *.inp *.TXT & popd
...but this only goes down one level of directories.
Can anyone help? Thanks in advance!
How to batch rename extensions. Navigate to the folder containing the files you want. Once there, launch command prompt from the folder menu by holding down shift and right clicking on an empty space. Once in command prompt, you can now use the “ren” (for rename) command to rename for example, .
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With