'Mass rename of file extensions recursively (windows batch)
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!
Solution 1:[1]
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
Solution 2:[2]
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" *.txt
COMMAND LINE:
FOR /R %x IN (*.js) DO ren "%x" *.txt
Up vote their responses, I am but a lowly formater...
Solution 3:[3]
Sometimes the renaming is necessary to change invalid characters inside the files and names. If you need to change a single character recursively:
Change character "?" for "ã" in folder names recursively:
FOR /R /D %x in (*?*) do @for /f "tokens=1-3* delims=?" %B in ("%x") DO ren "%x" "%~nBã%C"
Change character "?" for "ã" in file names recursively:
FOR /R %x in (*?*.*) do @for /f "tokens=1-3* delims=?" %B in ("%x") DO ren "%x" "%~nBã%C"
Change the chars for whatever you need. If you want to test your renaming commands before executing, just put an @echo between DO and ren:
DO @echo ren "%x" "%~nBã%C"
This will output the commands instead of executing them
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | john smith |
| Solution 2 | Roger Hill |
| Solution 3 | Luis Costa |
