本帖最后由 powerbat 于 2012-3-6 23:08 编辑
- @echo off
- set "file=jpg,mpg"
- set "fileD=%~d0" & set "fileP=%~p0"
- for /f "tokens=1,3* delims=.+ " %%a in ('wmic datafile where "drive='%fileD%' and path='%fileP:\=\\%' and (extension='%file:,=' or extension='%')" get name^,LastModified') do (
- set "t=%%a"
- rem 用for过滤掉wmic结果中的不可见字符
- for /f "delims=" %%i in ("%%c") do (
- setlocal enableDelayedExpansion
- set "t=!t:~,4!-!t:~4,2!-!t:~6,2! !t:~8,2!.!t:~10,2!.!t:~12!"
- for %%t in ("!t!") do (
- endlocal
- if not exist "%%~dpi%%~t%%~xi" (
- ren "%%~fi" "%%~t%%~xi"
- ) else (
- set n=1
- for %%u in ("%%~dpi%%~t_*%%~xi") do set /a n+=1
- setlocal enableDelayedExpansion
- for %%u in (!n!) do endlocal& ren "%%~fi" "%%~t_%%~u%%~xi"
- )
- )
- )
- )
- pause
复制代码
|