本帖最后由 yhcfsr 于 2018-4-16 18:26 编辑
- @echo off
- for /f "delims=" %%a in ('dir /a-d/s/b^|findstr "[0-9]"') do (
- call :get_num "%%~na" name
- setlocal enabledelayedexpansion
- ren "%%a" "!name!%%~xa"
- endlocal
- )
- pause&exit
-
- :get_num
- setlocal&set "name=%~1"
- :lp
- set "ch=%name:~,1%"
- rem 取一字,如果是数字,截8字:如果全数字就输出,否则继续逐字扫描
- echo;"%ch%"|findstr "[0-9]">nul&&(
- echo;%name:~,8%|findstr "^[0-9]*$">nul&&(endlocal&set "%2=%name:~,8%"&goto :eof)
- )
- set "name=%name:~1%"
- if "%name%"=="" endlocal&goto :eof
- goto :lp
复制代码 效率是没有的,同名判别是没做的(太简单懒得写)。所以祈祷你的8位数没有重复吧。 |