@echo off SetLocal EnableDelayedExpansion for %%i in (*.*) do ( set a=%%~ni set b=!a:~-2! mkdir !b! if not exist !b!^\%%i copy %%i !b! )