for %%i in (*.gif) do ( setlocal ENABLEDELAYEDEXPANSION set n=%%i ren %%i !n:~6,4!-!n:~4,2!-!n:~2,2!.gif endlocal )