本帖最后由 licunwei 于 2024-5-27 18:03 编辑
以下脚本是通过比对D:\SCETC\dataXml\路径下最新的*602和*603文件时间戳,如果2个文件的修改时间在1秒内,不执行任何动作。如果大于1秒就拷贝*603文件。我用了goto循环,虽然可以比对,但还是经常把2个文件 修改时间在1秒内的*603拷贝走了,我打算后面超过1秒的就拷贝后删除源文件,但现在测试都经常出错,更不敢添加删除命令了。求大神帮忙优化优化。
下面是当前脚本,求优化。- @echo off
- if "%1"=="hide" goto :ExecBat
- start mshta vbscript:createobject("wscript.shell").run("""%~f0"" hide",0)(window.close) && exit /b
- :ExecBat
- setlocal enabledelayedexpansion
- set "folder=D:\SCETC\dataXml\"
- set timestamp_602=0
- set timestamp_603=0
- set /a m=0
- set /a n=0
-
- for /F %%a in ('dir /b /s /o-d %folder%*602.xml') do (
- set /a m+=1
- set "timestamp_602!m!=%%~ta"
- )
-
- for /F %%b in ('dir /b /s /o-d %folder%*603.xml') do (
- set /a n+=1
- set "timestamp_603!n!=%%~tb"
- )
-
- set timestamp_602_hh=!timestamp_6021:~11,2!
- set timestamp_602_nn=!timestamp_6021:~14,2!
- set timestamp_602_formatted=!timestamp_602_hh!!timestamp_602_nn!
-
- set timestamp_603_hh=!timestamp_6031:~11,2!
- set timestamp_603_nn=!timestamp_6031:~14,2!
- set timestamp_603_formatted=!timestamp_603_hh!!timestamp_603_nn!
-
- set var602=!timestamp_602_formatted:~1!
- set var603=!timestamp_603_formatted:~1!
-
- set /a time_diff=%var603% - %var602%
-
- if %time_diff% LSS 1 (
- echo Both *602.xml and *603.xml flow generated within 1 second.
- ) else (
- echo Only *603.xml flow generated within 1 second. Deleting latest *603.xml flow...
- for /F %%c in ('dir /b /o-d %folder%*603.xml') do (
- set latest_flow=%%c
- md D:\交易失败流水\%date:~0,4%%date:~5,2%%date:~8,2% 2>nul
- xcopy /y %folder%%%c D:\交易失败流水\%date:~0,4%%date:~5,2%%date:~8,2%\
- call :end
- )
- )
-
- :end
- choice /t 1 /d y /n>nul
- goto ExecBat
复制代码
|