中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-25 21:51
47,813 topics / 349,918 posts / today 0 new / 48,275 members
DOS批处理 & 脚本技术(批处理室) » Please help the experts to modify this batch processing about time
Printable Version  4,093 / 26
Floor1 tianzizhi Posted 2006-10-22 22:21
高级用户 Posts 214 Credits 623
I'm now going to translate the content you provided. Please refer to the following:

The text you provided is in Chinese, and here is the translation:

I now need a batch processing. Starting from the current time, run a command after a specified time. I found the following batch processing program on the Internet, but it has a problem that it can't run correctly when the time is 0*:** because 0*+1 can't be added up. For example, when it's 08:30 in the morning, it can't run correctly, but it works after 10 o'clock because then adding 1 can be done, that is, the problem of the first number in the hour position being 0. How to solve this problem? Please help the experts modify the following batch processing so that it can be used within 24 hours a day, or provide other batch processing programs that meet my requirements. Thank you.

@echo off

setlocal ENABLEDELAYEDEXPANSION

set /a next_hour=0
set /a next_minute=0

for /F "tokens=1,2 delims=:" %%i in ('TIME /t') do (
rem Here 1 is the interval time, which can be adjusted according to your needs
set /a next_minute=%%j+1

set /a next_hour=%%i+1

if !next_minute! GEQ 60 (
set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
)

at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
Floor2 namejm Posted 2006-10-23 00:48
荣誉版主 Posts 1,737 Credits 5,226 From 成都
If there are leading zeros in the hours and minutes, the following code
can be modified to

Strangely, there is no case where the leading digit of the hour is zero on my machine.

[ Last edited by namejm on 2006-10-23 at 00:52 ]
Floor3 不得不爱 Posted 2006-10-23 00:55
超级版主 Posts 2,044 Credits 5,310 From 四川南充
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, which can be adjusted by yourself as needed
set a=%time:~0,2%
if %a:~0,1%==0 (set/a next_hour=%a:~1%+1) else set/a next_hour=a+1
set a=%time:~3,2%
if %a:~0,1%==0 (set/a next_minute=%a:~1%+1) else set/a next_minute=a+1
if %next_minute% GEQ 60 (set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
at !next_hour!:!next_minute! d:\Common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
Floor4 tianzizhi Posted 2006-10-23 01:23
高级用户 Posts 214 Credits 623
The moderator is really smart. It works now. Thank you. (When using time, the leading zero won't appear for the hour, but when using time /t, it will. Moderator, you can try it.)
Floor5 tianzizhi Posted 2006-10-23 01:38
高级用户 Posts 214 Credits 623
Moderator, please modify it again. It's okay to set the time after 10 o'clock, but it's still not working if set before 10 o'clock, and it shows: There should not be <set/a. at this time.

[ Last edited by tianzizhi on 2006-10-23 at 01:43 ]
Floor6 不得不爱 Posted 2006-10-23 02:43
超级版主 Posts 2,044 Credits 5,310 From 四川南充
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, which can be adjusted as needed
set/a next_hour=%time:~0,2%+1
set a=%time:~3,2%
if %a:~0,1%==0 (set/a next_minute=%a:~1%+1) else set/a next_minute=a+1
if %next_minute% GEQ 60 (set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal

[ Last edited by qwe1234567 on 2006-10-23 at 04:22 ]
Floor7 不得不爱 Posted 2006-10-23 02:56
超级版主 Posts 2,044 Credits 5,310 From 四川南充
——————————————————Moderation Record——————————————————
Executor: qwe1234567
Description: Duplicate topic posted {Please help me modify this batch processing about time} in {DOS Troubleshooting & Problem Discussion (Help Desk)}. Please do not post duplicate topics.
Action: Merge the topics and delete the original poster's duplicate topic post
————————————————————————————————————————
Floor8 tianzizhi Posted 2006-10-23 03:59
高级用户 Posts 214 Credits 623
The moderator missed a sentence, set a=%time:~0,2%
Thank you very much for letting me learn a lot of knowledge.

@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, you can adjust it according to your needs
set a=%time:~0,2%
set/a next_hour=a+1
set a=%time:~3,2%
if %a:~0,1%==0 (set/a next_minute=%a:~1%+1) else set/a next_minute=a+50
if %next_minute% GEQ 60 (set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal

Now I've got it, after struggling for a long time, let me learn two different methods. One is a brain teaser, and the other is a rigorous DOS learning process. It's very good. It also let me learn the use of set offset and length.
Still, it's faster to learn things in application, hehe. It is suggested that friends learning DOS should learn in practice, and ask more questions for themselves.
Floor9 不得不爱 Posted 2006-10-23 04:26
超级版主 Posts 2,044 Credits 5,310 From 四川南充
Let's optimize it a bit. Here's the modified code:

@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, you can adjust it as needed
set /a next_hour=%time:~0,2% + 1
set /a next_minute=1%time:~3,2% - 100 + 1
if %next_minute% GEQ 60 (
set /a next_minute=!next_minute! - 60
set /a next_hour=!next_hour! + 1
if !next_hour! GEQ 24 set /a next_hour=!next_hour! - 24
)
at !next_hour!:!next_minute! d:\common\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
Floor10 tianzizhi Posted 2006-10-23 04:43
高级用户 Posts 214 Credits 623
Combine the two into one, good! I'll take both.
Floor11 tianzizhi Posted 2006-10-23 04:52
高级用户 Posts 214 Credits 623
Let me ask the moderator again. That GEQ is the meaning of greater than, then what is the one for less than? Why haven't I seen them before? In batch processing, the > < can't be used for comparison, right? Where can I find these similar symbols?
Floor12 lxmxn Posted 2006-10-23 05:50
版主 Posts 4,938 Credits 11,386

EQU - equals
NEQ - not equals
LSS - less than
LEQ - less than or equal to
GTR - greater than
GEQ - greater than or equal to

The reason why symbols like < and > cannot be used to judge size is that in batch processing, <, >, >> are all redirection symbols and have special uses.
Floor13 tao0610 Posted 2006-10-24 05:25
高级用户 Posts 218 Credits 579
In the line `at !next_hour!:!next_minute! d:\常用\d.vbs`, `!next_hour!` and `!next_minute!` are also variables. The exclamation marks here are different from `%` in terms of usage in the context of batch scripting. In some cases, `!var!` is used for delayed expansion in batch when enabled with `setlocal enabledelayedexpansion`, while `%var%` is the normal expansion. But in this specific context related to the `at` command usage here, the main point is that they are variable placeholders with different delimiters from `%`.
Floor14 78586862 Posted 2006-10-28 08:02
初级用户 Posts 14 Credits 25
Originally posted by qwe1234567 at 2006-10-23 04:26 AM:
Optimize it for you again
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem Here 1 is the interval time, you can adjust it according to your needs
set/a next_hour=%time:~0,2%+1
set/a next_minute=1%time:~3,2%-100+1
if ...



May I ask the moderator, what does this interval of 1 represent? Is it 1 minute or 1 hour?
If I want to run the specified file after 20 minutes, how should I modify it? If it is 4 hours, how should I modify it?
Also, does this batch processing need to be run again after running once? It will run the specified file by itself when the specified time comes, right? Is it in the process all 24 hours?
at !next_hour!:!next_minute! d:\common\d.vbs
This refers to running the specified file.
Then this schtasks /delete /tn "zhang" /f
Does it mean to specify deleting the file named zhang under the F drive?
Please tell this newbie. I'm also learning. If this batch processing is really that magical, it's very important to me. Thank you.
Floor15 不得不爱 Posted 2006-10-28 09:04
超级版主 Posts 2,044 Credits 5,310 From 四川南充
If you want to run a specified file after 20 minutes, just change 1 to 20.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023