Board logo

标题: [日期时间] 请教:批处理for中每个循环的起始时间%time%都一样没有变化 [打印本页]

作者: yyii    时间: 2020-4-20 10:45     标题: 请教:批处理for中每个循环的起始时间%time%都一样没有变化

  1. @echo off
  2. echo starttime,%time%
  3. echo starttime,%time%>timeresult.txt
  4. for /r %%i in (*.txt) do (
  5. echo %%~nxi
  6. call set t1=%%time%%
  7. echo waiting 3 second ...
  8. ping -n 3 127.1>nul
  9. call set t2=%%time%%
  10. call echo %%t1%%,%%t2%%
  11. call echo %%~nxi,%%t1%%,%%t2%%>>timeresult.txt
  12. )
  13. echo endtime,%time%>>timeresult.txt
  14. echo endtime,%time%
  15. echo complete
复制代码
set t1, set t2 前不加call也试过了。
谢谢指点!
作者: Batcher    时间: 2020-4-20 11:42

回复 1# yyii
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. echo starttime,!time!
  4. echo starttime,!time!>timeresult.txt
  5. for /r %%i in (*.txt) do (
  6.     echo %%~nxi
  7.     set t1=!time!
  8.     echo waiting 3 second ...
  9.     ping -n 3 127.1 >nul
  10.     set t2=!time!
  11.     echo !t1!,!t2!
  12.     echo %%~nxi,!t1!,!t2!>>timeresult.txt
  13. )
  14. echo endtime,!time!>>timeresult.txt
  15. echo endtime,!time!
  16. echo complete
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2