@echo off setlocal enabledelayedexpansion for %%f in (*) do ( if not "%%~ff"=="%~f0" ( set "filename=%%~nf" if not exist "!filename!" ( mkdir "!filename!" ) move "%%f" "!filename!\...