@echo off for %%i in (*.txt) do (set fname=%%~ni) & call :renameFile goto :eof :renameFile ren "%fname%.txt" "%fname:~0,-3%.txt" goto :eof