逐个字符判断,适配了 如 01p12p34p.jpg 则取01p12p,保留p大小写
- @echo off
- cd /d "%~dp0"
- for /l %%l in (0,1,9) do (
- set #"%%l"=1
- )
- for /f "delims=" %%i in ('dir /b /a-d *.jpg') do (
- set n=%%~ni
- setlocal enabledelayedexpansion
- if defined n (
- set _n=!n!
- for %%l in (128 64 32 16 8 4 2 1) do (
- if "!_n:~%%l!" neq "" (
- set /a len+=%%l
- set _n=!_n:~%%l!
- )
- )
- for /l %%l in (0,1,!len!) do (
- set m=!n:~%%l,1!
- if "!m!" neq "" (
- if not defined folder (
- if defined #"!m!" (
- set str=!str!!m!
- ) else if /i "!m!" equ "p" (
- if defined str (
- if "!str:~0,1!" neq "0" (
- set folder=!n:~0,%%l!!m!
- ) else (
- set str=
- )
- )
- ) else (
- set str=
- )
- )
- )
- )
- )
- if defined folder (
- md "!folder!"
- move "!n!%%~xi" "!folder!\"
- echo move "!n!%%~xi" "!folder!\"
- )
- endlocal
- )
- pause
复制代码
|