回复 20# fyubo - @echo off
- set "file=jpg,mpg"
-
- set "Ext=*.%file:,= *.%"
- rem 先重命名一次,加一段文件名中不会出现的字符串,防止可能的文件名重复问题。
- for /f "delims=" %%a in ('dir /b %Ext%') do (
- ren "%%~fa" "powerbat@bathome_%%~nxa"
- )
-
- set "FileD=%~d0" & set "FileP=%~p0"
- set "Ext=and (extension='%file:,=' or extension='%')"
- set "Filter=drive='%FileD%' and path='%FileP:\=\\%' %Ext%"
- for /f "tokens=1,3* delims=.+ " %%a in ('wmic datafile where "%Filter%" get name^,LastModified') do (
- set "t=%%a"
- rem 用for过滤掉wmic结果中的不可见字符
- for /f "delims=" %%i in ("%%c") do (
- set "f=%%~fi"
- set "p=%%~dpi"
- set "n=%%~ni"
- set "x=%%~xi"
- setlocal enableDelayedExpansion
- set "t=!t:~,4!-!t:~4,2!-!t:~6,2! !t:~8,2!.!t:~10,2!.!t:~12!"
- if not exist "!p!!t!!x!" (
- ren "!f!" "!t!!x!"
- ) else if "!t!" neq "!n!" (
- set n=1
- for %%u in ("!p!!t!_*!x!") do set /a n+=1
- ren "!f!" "!t!_!n!!x!"
- )
- endlocal
- )
- )
- pause
复制代码
|