本帖最后由 ivor 于 2016-2-20 12:50 编辑
回复 1# wzf1024 - @echo off&setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /b *.txt') do (
- set "name=%%a"
- rename "%%a" !name:~-6!
- )
- pause
复制代码 代码很容易,但是你的文件很多,只留两个字符,很容易会文件名重复
刚出炉的新代码:有多少重复的都没问题- @echo off&setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /b *.txt') do (
- set "name=%%a"
- rename "%%a" "!name:~-6!" 2>nul || call :repeat
- )
- echo 已经全部处理...... & pause>nul
- goto :EOF
- :repeat
- set /a num+=1
- rename "!name!" "!name:~-6,2!(!num!)!name:~-4!" && goto :EOF || goto :repeat
复制代码
|