本帖最后由 neorobin 于 2012-4-20 15:32 编辑
回复 12# tousyo88
WinXP CHS 32 位环境下
%%~ti 的方式也是不能输出 秒 的
下面仍使用 wmic datafile, 不受日期时间格式影响, 如果需要特定的排序方式, 可以在 16 行用 dir 适当的参数修改一下
工作目录使用全路径, 批处理文件 可以放在 除 工作目录之内 的任何地方- @echo off & setlocal enabledelayedexpansion
-
- set "fn=列表文件.txt"
- set "fdir=d:\szt" & rem 不含引号的工作目录全路径
-
- 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"
-
- cd /d "!fdir!"
- if exist "!fn!" del /f /q "!fn!"
- if exist "TempWmicBatchFile.bat" del /f /q "TempWmicBatchFile.bat"
-
- <nul > "!temp!\!fn!" (
- for /f "tokens=*" %%a in ('dir /b /a-d') do (
- set "pth=%%~fa"
- set /p "=%%~nxa|%%~za|"
- for /f %%t in ('wmic datafile where name^="!pth:\=\\!" get !filetime! ^| find "."') do (
- set "ft=%%t"
- echo !ft:~0,8!^|!ft:~8,2!:!ft:~10,2!:!ft:~12,2!
- )
- )
- )
-
- move "!temp!\!fn!" "!fdir!"
- start "" "!fdir!\!fn!"
复制代码
|