|
tianzizhi
高级用户
   
积分 622
发帖 214
注册 2006-9-22
状态 离线
|
『楼 主』:
请高手们帮忙修改一下这个关于时间的批处理
使用 LLM 解释/回答一下
我现在需要一个批处理,以现在的时间为起点,过指定的时间后运行一个命令.
我在网上找到下面的批处理程序,但它有一个问题,就是当时间为0*:**时就不能正确运行了,因为0*+1加不起来呀,例如:当早上08:30时就不能正确运行了,但到了10点以后就行了,因为这时再加1能加起来了,就是小时位上第一个数为0的问题,如何解决这个问题呀.
请高手们帮忙修改一下下面的批处理,使它在一天24小时内都能用,或提供一下能满足我要求的其它批处理程序,谢谢.
@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 这里1是间隔时间,可以根据需要自己调节
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:\常用\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
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
|
|
2006-10-22 22:21 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
如果小时数和分钟的首位上出现0,可以把如下代码
set /a next_minute=%%j+1
set /a next_hour=%%i+1
修改为
set /a next_minute=1%%j-100+1
set /a next_hour=1%%i-100+1
奇怪的是,在我的机子上并没有出现小时数首位为0的情况。
Last edited by namejm on 2006-10-23 at 00:52 ]
If there are leading zeros in the hours and minutes, the following code
set /a next_minute=%%j+1
set /a next_hour=%%i+1
can be modified to
set /a next_minute=1%%j-100+1
set /a next_hour=1%%i-100+1
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 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-23 00:48 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem 这里1是间隔时间,可以根据需要自己调节
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:\常用\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
@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
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-10-23 00:55 |
|
|
tianzizhi
高级用户
   
积分 622
发帖 214
注册 2006-9-22
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
版主真聪明,现在可用了,谢谢,(用time 时小时首位不会出现0的,但用time /t 时就会出现了,版主试试).
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.)
|
|
2006-10-23 01:23 |
|
|
tianzizhi
高级用户
   
积分 622
发帖 214
注册 2006-9-22
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
版主麻烦你再改一下,把时间设成10点以后还行的,但设成10点以前还是不行的,显示:此时不应有<set/a.
Last edited by tianzizhi on 2006-10-23 at 01:43 ]
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 ]
|
|
2006-10-23 01:38 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem 这里1是间隔时间,可以根据需要自己调节
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:\常用\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
Last edited by qwe1234567 on 2006-10-23 at 04:22 ]
@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 ]
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-10-23 02:43 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
——————————————————版务纪录——————————————————
执行:qwe1234567
说明:重复发表主题 {请高手们帮忙修改一下这个关于时间的批处理} 在{DOS疑难解答 & 问题讨论 (解答室)} 请不要发表重复主题
操作:合并主题,并且删除楼主的重复主题帖子
————————————————————————————————————————
——————————————————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
————————————————————————————————————————
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-10-23 02:56 |
|
|
tianzizhi
高级用户
   
积分 622
发帖 214
注册 2006-9-22
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
版主少了一句呀,set a=%time:~0,2%
非常感谢你让我学到很多知识.
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem 这里1是间隔时间,可以根据需要自己调节
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:\常用\d.vbs
schtasks /delete /tn "zhang" /f
endlocal
这下可会了,折腾了半天了,让我学会了两种不同的方法呀,一个是脑筋急转变,一个是严谨的dos学习过程,很不错,也让我学会了set的偏移量和长度的使用,
还是在应用中学东西快呀,呵呵,建议学dos的朋友要在实践中学呀,多给自己提问.
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.
|
|
2006-10-23 03:59 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-23 04:26 |
|
|
tianzizhi
高级用户
   
积分 622
发帖 214
注册 2006-9-22
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
集两者与一,好!都要了.
Combine the two into one, good! I'll take both.
|
|
2006-10-23 04:43 |
|
|
tianzizhi
高级用户
   
积分 622
发帖 214
注册 2006-9-22
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
再问一下版主,那个GEQ是大于的意思吧,那小于是哪个呀,怎么以前没有见过它们呀,在批处理里经常比较大小的> <不能用是吗,类似的这些符号在哪里可以找到呢??
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?
|
|
2006-10-23 04:52 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
EQU - 等于
NEQ - 不等于
LSS - 小于
LEQ - 小于或等于
GTR - 大于
GEQ - 大于或等于
之所以不能用< >之类的符号判断大小,是因为在批处理中,<、>、>>都是重定向符号,有特殊的用处。
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.
|
|
2006-10-23 05:50 |
|
|
tao0610
高级用户
    朦胧的世界
积分 579
发帖 218
注册 2006-10-24
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
at !next_hour!:!next_minute! d:\常用\d.vbs
中的!next_hour!和!next_minute!也是变量吗?
两边加的叹号和%相似吗?
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 `%`.
|
|
2006-10-24 05:25 |
|
|
78586862
初级用户
 
积分 25
发帖 14
注册 2006-10-28
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by qwe1234567 at 2006-10-23 04:26 AM:
在给你优化下
@echo off
setlocal ENABLEDELAYEDEXPANSION
rem 这里1是间隔时间,可以根据需要自己调节
set/a next_hour=%time:~0,2%+1
set/a next_minute=1%time:~3,2%-100+1
if ...
请问版主 这个间隔是 1 这个1代表的时间是多久 是1分还是1小时
如果我要20分以后运行指定文件 那应该怎么修改 如果是4小时又应该怎么修改呢
还有 这个批处理 是不是运行一次以后 就不需要在运行了 到了指定时间就会自己运行指定的 文件呢 它是不是24小时都在进程里的
at !next_hour!:!next_minute! d:\常用\d.vbs
这个是指运行的指定文件
那这个 schtasks /delete /tn "zhang" /f
是指定要删除 F盘下的 zhang名字的文件吗
麻烦告诉我这个菜鸟 我也正在学习 如果这个批处理真的那么神奇的话 就对我很重要 谢谢了
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.
|
|
2006-10-28 08:02 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-28 09:04 |
|