回复 1# licunwei
一楼代码用dir简报获取文件时间戳的精度是分钟级
还是用powershell功能获取秒级精度的文件时间戳更方便,只是powershell的首启速度较慢而已...
以下代码假设*603*.xml文件修改时间 ‘总是晚于’ *602*.xml文件修改时间
- @echo off &setlocal enabledelayedexpansion
- set "folder=D:\SCETC\dataXml\"
- :[Loop]
- (call :getSofF "%folder%*602.xml" f602 h602 s602)
- (call :getSofF "%folder%*603.xml" f603 h603 s603)
- if !s602! gtr !s603! set/a "s603+=(24+h603)*3600"
- set/a "dt=!s603!-!s602!"
- if !dt! gtr 1 (xcopy /y /i "!f603!" "D:\交易失败流水\%date:~0,4%%date:~5,2%%date:~8,2%\")
- goto[Loop]
- :getSofF
- for /f "tokens=1* delims=:" %%A in (' dir /b/o-d/tw "%~1"^|findstr /n ".*"^|findstr /lbc:"1:" ') do (
- for /f "delims=" %%t in (' powershell "(Get-ChildItem """%%B""").LastWriteTime" ') do (
- set "t=%%t" &for /f "tokens=1-3 delims=:" %%a in ("!t:~-8!") do for %%k in (%%a %%b %%c) do (
- set "k=%%k" &if "!k:~,1!"=="0" (set "ts=!ts!:!k:~-1!") else set "ts=!ts!:!k!"
- )
- )
- for /f "tokens=1-3 delims=:" %%a in ("!ts:~1!") do (set "%~3=%%a"&set/a "s=%%a*3600+%%b*60+%%c")
- set "%~2=%%B" &set "%~4=!s!"
- )
- exit/b
复制代码
|