setlocal ENABLEDELAYEDEXPANSION for /f %%d in ('dir /ad /b') do ( set DN=%%d md "!DN:~0,8!" move "!DN!" "!DN:~0,8!" )