I’m trying to rename approx 400,000 file names to remove all the text in brackets, all the available software just freezes when presented with the task.
Example_Filename (with random text in brackets).ext needs to become: Example_Filename.ext
Can anyone write me the code for a batch file to do this? All the files are in one folder, text in brackets can appear anywhere in the filenames, no files only have text in brackets.
Thanks.
@echo off & setlocal enabledelayedexpansion
cd Here your folder name
set odd=1,3,5,7,9,11,13
set evn=2,4,6,8,10,12,14
:: ignore any files with no parens
for /f “tokens=*” %%a in (‘dir /b *(*.txt’) do (
set x=%%a
:: is ths really necessary? or “overkill”. Attempts to hande files beginning with (
set t=!x:~0,1!
set x=!x:^)^(=!
if “!t!” equ “(” (
for /F “tokens=%evn% delims=()” %%b in (“!x!”) do ren “%%a” “%%b%%c%%d%%e%%f%%g%%h”
) else (
for /F “tokens=%odd% delims=()” %%b in (“!x!”) do ren “%%a” “%%b%%c%%d%%e%%f%%g%%h”
)
)
::======== end batch
fully tested.