纯批其实不好玩- @echo off & setlocal enabledelayedexpansion
-
- :: 功能:
- :: 文件名前面相同多个的创建文件装起来
- :: 无相同得单独一个文件不管
-
- for /f "delims=" %%i in ('dir /a-d /b') do (
- set "name=%%~ni" & set "n=" & set "_n=" & set "pre="
- for %%j in (0,1,2,3,4,5,6,7,8,9) do (
- set name=!name:%%j=!
- set suf=!name:~-1!
- )
- set "name=%%~ni"
- rem 不想用goto,就假设名字中没有20个相同的字符
- for /l %%j in (1,1,20) do (
- if not defined n (
- for %%k in (!suf!) do set name=!name:*%%k=!
- set /a "tmp=name"
- if "!name!"=="!tmp!" set n=!name!
- )
- )
- set "name=%%~ni" & set "tmp="
- if defined n (
- for %%j in (!n!) do set pname="!name:%%j=" "!"
- for %%j in (!pname!) do (
- if defined pre (
- if "%%~j"=="" (
- set tmp=!n!
- ) else (
- if defined tmp (
- set "pre=!pre!!tmp!" & set "tmp="
- )
- set pre=!pre!!n!%%~j
- )
- ) else set pre=%%~j
- )
- rem 文件名有空格时影响set /a,先替换一下,完事换回来
- set pre=!pre: ={_}!
- set /a "#fnum[!pre!]+=1,_n=#fnum[!pre!]"
- set pre=!pre:{_}= !
- if !_n! gtr 1 (
- for /f "delims=" %%j in ("!pre!") do (
- if not "!%%j!"=="" (
- echo;文件夹:[!pre!]
- echo; 1. !%%j!
- rem echo;拷贝!%%j! --^> 文件夹%%j
- set "!pre!="
- )
- )
- echo; !_n!. %%~nxi
- rem echo;拷贝!name! --^> 文件夹!pre!
- ) else set !pre!=%%~nxi
- )
- )
- echo;--------------------------------------
- echo;打印一下数量,{_}代表空格
- set #fnum
-
- pause & exit /b
复制代码
|