In my case I had a directory with 800+ files ending with .StoredProcedure.sql
(they were scripted with SSMS).
The solutions posted above didn't work. But I came up with this:
(Based on answers to batch programming - get relative path of file)
@echo off
setlocal enabledelayedexpansion
for %%f in (*) do (
set B=%%f
set B=!B:%CD%\=!
ren "!B!" "!B:.StoredProcedure=!"
)
The above script removes the substring .StoredProcedure
from the filename. I'm sure it can be adapted to cover more cases, ask for input and be overall more generic.