1.过滤文件名中所有数字、汉字、特殊字符(含空格)
@echo off for %%a in (*.*) do ( if "%%~nxa" neq "%~nx0" ( set "name=%%~na" setlocal enabledelayedexpansion set name1=!name! call :lp ren "!name!%%~xa" "!nam!%%~xa" set "nam=" endlocal ) ) pause :lp if defined name1 ( set "var=!name1:~,1!" if "!var!" leq "Z" ( if "!var!" geq "a" ( set "nam=!nam!!var!" )) set "name1=!name1:~1!" goto lp )
2.不过滤数字
@echo off setlocal enabledelayedexpansion set "n=1000" for /f "delims=" %%a in ('dir/b *.jpg') do call :a "%%a" for /f "delims=" %%a in ('dir/b/od *.jpg') do set/a "n+=1"&ren "%%a" "!n:~-3!%%~xa" exit :a ren "%~1" "%random%%~x1" || goto a
貌似含正则表达式语法,真心没看懂!以后研究吧。
参考: