::文件批量命名并按xxx_000x排序

@echo off
::文件批量命名并按xxx_000x排序
setlocal enabledelayedexpansion
color 0a

set "lastName=x"
set /A num=0
for /f %%i in ('dir /b /a /o:n "*.png"') do (
	IF NOT "%%i"=="%~n0%~x0" (
		for /f "tokens=1 delims=_" %%j in ("%%i") do (
			IF NOT "!lastName!" == "%%j" (
				set /A num=1;
				set lastName=%%j
			) 
			if !num! lss 1000 set "name=0!num!"
			if !num! lss 100 set "name=00!num!"
			if !num! lss 10 set "name=000!num!"
			echo "%%~i" "%%j_x!name!%%~xi"
			rename "%%~i" "%%j_x!name!%%~xi"
			set /A num+=3
		)
	)
)
:end
@echo 已结束
pause

posted on 2013-07-12 16:05  几百人有爱  阅读(400)  评论(0编辑  收藏  举报