谢谢 5 楼 gawk 提醒了我 wmic, 改了下- @echo off & setlocal enabledelayedexpansion
-
- set "fn=列表文件.txt"
- set "fdir=szt"
-
- REM 备份原始日期时间格式
- for /f "tokens=2*" %%a in ('reg query "HKCU\Control Panel\International" /v sShortDate^|find/i"sSh"') do set "sShortDate=%%~b"
- for /f "tokens=2*" %%a in ('reg query "HKCU\Control Panel\International" /v sTimeFormat^|find/i"sTi"') do set "sTimeFormat=%%~b"
-
- REM 修改日期时间格式
- >nul reg add "HKCU\Control Panel\International" /v sShortDate /t REG_SZ /d "yyyyMMdd" /f
- >nul reg add "HKCU\Control Panel\International" /v sTimeFormat /t REG_SZ /d "HH:mm:ss" /f
-
- set "timeField=C"
- set /p "timeField=请选择时间类型, 默认=!timeField! (C 创建时间; A 上次访问时间; W 上次写入的时间):"
- for %%a in ("C CreationDate" "A LastAccessed" "W LastModified"
- ) do for /f "tokens=1-2" %%b in ("%%~a") do if /i %%b==!timeField! set "filetime=%%c"
-
- if exist "%~dp0!fdir!\!fn!" del /f /q "%~dp0!fdir!\!fn!"
- > "!fn!" (
- for /f "tokens=1-3*" %%a in (
- 'dir !fdir! /a-d /od /t!timeField! /-c^|findstr "^[1-9].*[0-9][0-9]:[0-9][0-9]"') do (
- <nul set /p "=%%d|%%c|%%a|"
- set "pth=%~dp0!fdir!\%%d"
- for /f %%t in ('wmic datafile where name^="!pth:\=\\!" get !filetime! ^| find "."') do (
- set "ft=%%t"
- echo !ft:~8,2!:!ft:~10,2!:!ft:~12,2!
- ) ) )
- move "!fn!" "%~dp0!fdir!\"
- start "" "%~dp0!fdir!\!fn!"
-
- REM 还原原始日期时间格式
- >nul reg add "HKCU\Control Panel\International" /v sShortDate /t REG_SZ /d "!sShortDate!" /f
- >nul reg add "HKCU\Control Panel\International" /v sTimeFormat /t REG_SZ /d "!sTimeFormat!" /f
- exit
复制代码
|