1.网上找了一段代码修改,运行错误,求指正。
2.下面代码添加的是修改时间,如果是创建时间,代码又如何写?- @echo off
- setlocal enabledelayedexpansion
-
- set count=1
- for /f "delims=" %%a in ('dir /b /a-d/tc' ) do (
- set "name=%%a"
- set "ext=%%~xa"
- set "datestring=%%~ta"
- echo !datestring!
- set "year=!datestring:~0,4!"
- set "month=!datestring:~5,2!"
- set "day=!datestring:~8,2!"
- set "hour=!datestring:~11,2!"
- set "minute=!datestring:~14,2!"
- :: %%~ta提取的时间格式为2024-07-17 13:50不包含秒
- set "second=!datestring:~17,2!"
- set "newname=!year!!month!!day!_!hour!!minute!!second!"
- echo !ext!
- echo !datestring!
- if not "!name!"=="!newname!"(
- if exist "!newname!"(
- set "newname=!year!!month!!day!_!hour!!minute!!second!_!count!!ext!"
- set /a count+=1
- )
- ren !name! "!newname!"
- )
- )
- endlocal
- pause
复制代码
|