@echo off
setlocal enabledelayedexpansion
set num=4
for /f "delims=" %%a in ('dir /a-d /b *.*') do (
if not "%%~nxa"=="%~nx0" (
set tmp=%%~na
set tmp=!tmp:~0,%num%!
if not exist "!tmp!\" (
md "!tmp!\"
move "%%~a" "!tmp!\"
) else (
move "%%~a" "!tmp!\"
)
)
)
echo end...
pause