把文件名存放在变量里 不知道文件多时怎么样- @echo off & setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /b/ad') do (
- set /a_%%a=0,m+=1
- set files=!files! %%a
- for /f "delims=" %%b in ('dir /b/a-d "%%~fa\*.jpg"') do (
- set /a _%%a+=1
- set $%%a_!_%%a!=%%b
- )
- )
- for %%a in (!files!) do set/a n+=_%%a
- set /a p=n/m,q=n%%p
- for %%a in (!files!) do (
- if !q! gtr 0 (
- set /a q-=1,#p_%%a=p+1
- ) else set /a#p_%%a=p
- if !_%%a! lss !#p_%%a! (
- set files=!files: %%a=!
- set "$#=!$#!:%%a"
- ) else if !_%%a! equ !#p_%%a! set files=!files: %%a=!
- )
- if not "#!files: =!" == "#" for %%a in (!files!) do (
- set /a i=_%%a - #p_%%a
- for /l %%b in (1,1,!i!) do (
- for /f "delims=:" %%c in ("!$#!") do (
- if !_%%c! geq !#p_%%c! (
- set "$#=!$#:*%%c:=!"
- for /f "delims=:" %%c in ("!$#!") do set "f=%%c"
- ) else set "f=%%c"
- )
- for %%c in ("!f!") do (
- move "%%a\!$%%a_%%b!" "%%~c\"
- set /a _%%~c+=1
- )
- )
- )
- pause
复制代码
|