|
jastyg
中级用户
  
积分 219
发帖 82
注册 2005-10-29
状态 离线
|
『楼 主』:
[原创]计划任务小程序 [06.12更新]
使用 LLM 解释/回答一下
自己没有学习过DOS,恐怕这个要归结于接触电脑的时间比较晚,还好发现了这个好地方。那个开心啊~~~而且感觉只要来这里就一定有收获!
首先不算多也在坛子里泡大半年了,自己水平很低报着学习的态度来看待任何问题,不过有幸的是整个论坛的氛围很好,除了板油积极的态度,更重要的这里有着一帮热心并且水平很高的斑竹。可以说是我们很好的老师,在此向帮助过我的朋友表示感谢。
花了2天时间写了这个小程序,主要是想把在这里的所学集中的使用一次,当然是比较低级的程序,希望大家不要见笑并给予支持。
请各位看看有什么写的不妥或者不正确的地方,很乐意接受意见。
更改时间:2006.6.9 10时
早上花了点时间加了批注,等于是自己再复查一遍以有的问题,果然发现几个地方的问题。:P,附件没有更新存在几个大小写的问题
更改时间2006.6.12 13时,加入了对时间和日期的检验
==========ETIME========
@echo off
color 1f
echo.
echo 定时计划工具 VER:1.0
echo by:风弛网络,jastyg
echo Email:support@efengchi.com
echo HTTP://WWW.EFENGCHI.COM
echo for xp/2k3
echo.
echo.
rem ++++++++++++++++++++外部命令行模式的处理+++++++++++++++++++++++++++
rem ===================检测外部是否输入为空后者是帮助信息============
if "%1!%"=="!" goto guihelp :如果外部为空,则使用图形页面
if "%1%"=="/?" goto help :外部输入/?则出现DOS的帮助提示
if "%1%"=="/h" goto help :同上,输入/h
if "%1%"=="/H" goto help :同上,分别给出了大小写。
for %%i in (0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31) do if "%1"=="%%i" goto kaishi
goto warng2
rem====================开始对外部输入进行设置和检验==================
:kaishi
if "%1"=="0" set d=0&set riqi=0& goto t :初始如果日期为0
set /a tmp=%date:~8,3%+0 >nul :判断日期是否为8号或者9号,以接下文(解决8,9的无效字符方法)
cls :清屏
if errorlevel 9167 goto tmp1 :接上文接受是否为8号或者9号
goto tmp2
rem====================对8,9号的日期进行确定========================
:tmp1
echo %date:~8,2% >tem.txt :导出当前的日期到临时文件
find "08" tem.txt >nul :从临时文件寻找是否含有数值08,以接下文
if not errorlevel 1 set riqi=8&goto tmp3 :判断如果含有08,则设置riqi变量为8,跳转到TMP3标签
find "09" tem.txt >nul :从临时文件寻找是否含有数值09,以接下文
if not errorlevel 1 set riqi=9&goto tmp3 :判断如果含有09,则设置riqi变量为9,跳转到TMP3标签
rem====================对外部日期不为0,8,9的情况下的处理===============
:tmp2
set /a riqi=%date:~8,2%+0 :对日期进行十位为空去0处理
:tmp3
set /a d=%1+0 :对用户输入的日期十位为空去0处理
rem===================对外部时间,用户命令进行处理=================================
:t
if exist tem.txt del tem.txt :对日期设置完成所留下的临时文件的清理
set t=%2 :定义变量T为用户输入的时间
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,) do if "%t:~0,2%"=="%%i" goto CRC
goto warng2
:CRC
if "%t:~2,1%"==":" goto CRC1
goto warng2
:crc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto bcmd
goto warng2
:bcmd
set cmd=%~3 :定义运行的程序为用户输入
if "%~3!"=="!" goto command :如果用户不输入,则跳到默认设置给的值,到COMMAND
goto 4
:command
set cmd=c:\windows\风弛备份.bat :设置默认运行命令
rem===================设置外部循环选项命令==========================================
:4
if "%4!%"=="!" goto 41 :判断是否为空并相对跳转
if "%4%"=="n" goto 41 :判断是否为小写n并相对跳转
if "%4%"=="N" goto 41 :是否为大写N并相对跳转
if "%4%"=="y" goto 42 :是否为小写y并相对跳转
if "%4%"=="Y" goto 42 :是否为大写Y并相对跳转
rem===================设置默认及不循环==============================================
:41
set rem=echo. :定义变量为echo.
goto start :跳转到日期时间的检验部分
:42
set rem=goto start :定义变量为goto 语句,实现循环
set yanchi=ping -n 60 127.1^>nul :为防止时间在指定时间内多次运行,设置了延迟1分钟
goto start :跳转到日期时间的检验部分
echo.
rem ++++++++++++++++++++图形化的设置和配置处理++++++++++++++++++++++++++++++++++++++++
rem===================图形化帮助提示================================================
:guihelp
echo 请等待......
ping -n 1 ping 127.1 >nul
cls
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo +用法1:直接运行此文件,跟向导走。需要帮助请输入?或者h +
echo +日期格式:例如9号,可以输入9或者09 +
echo +时间格式采用24小时制,即:20:50 (精度到分钟) +
echo +用法2:命令行模式; +
echo +语法:etime 日 时间 命令(最好写完整路径) Y/N(是否循环运行,默认为N) +
echo +例:etime 7 20:20 notepad.exe (7日,20:20运行 NOTEPAD这个程序,并且不循环) +
echo +例:etime 0 20:20 notepad.exe Y (20:20运行 NOTEPAD这个程序,并且循环) +
echo +DOS下输入 etime /? 或者 etime /h 得到帮助 +
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem===================对用户输入日期进行检测和定义==================================
:begin
echo 请输入日期
set d1=enter :定义一个值给D1,用来下文的用户输入为空的检测
set /p d1= :用户自定义输入
if "%d1%"=="?" goto guihelp :图形帮助的调用
if "%d1%"=="h" goto guihelp :同上
if "%d1%"=="H" goto guihelp :同上
if "%d1%"=="enter" goto warng :检测用户输入是否为空,并进行相对处理
if "%d1%"=="0" set d=0&set riqi=0& goto shij :检测用户输入是否为0,并相对定义
for %%i in(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,) do if "%
d1%"=="%%i" goto 89
goto warng
:89
set /a tmp=%date:~8,3%+0 >nul :判断日期是否为8号或者9号,以接下文(解决8,9的无效字符方法)
cls
if errorlevel 9167 goto tem1 :接上文接受是否为8号或者9号,并相关跳转
goto tem2
rem====================对8,9号的日期进行确定,同上TMP1========================
:tem1
echo %date:~8,2% >tem.txt
find "08" tem.txt >nul
if not errorlevel 1 set riqi=8&goto tem3
find "09" tem.txt >nul
if not errorlevel 1 set riqi=9&goto tem3
rem====================对日期不为0,8,9的情况下的处理,同上TMP2===============
:tem2
set /a riqi=%date:~8,2%+0
:tem3
set /a d=%d1%+0
rem===================对时间,用户命令进行处理=================================
:shij
if exist tem.txt del tem.txt :对日期设置完成所留下的临时文件的清理
cls
echo 请输入时间
set t=enter :定义一个值给T,用来下文的用户输入为空的检测
set /p t= :用户自定义输入
if "%t%"=="?" goto guihelp :图形帮助的调用
if "%t%"=="h" goto guihelp :同上
if "%t%"=="H" goto guihelp :同上
if "%t%"=="enter" goto warng1 :检测用户输入是否为空,并进行相对处理
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,?,h,H) do if "%t:~0,2%"=="%%i" goto TCRC
goto warng1
:TCRC
if "%t:~2,1%"==":" goto TCRC1
goto warng1
:tcrc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto cmd
goto warng1
rem==================对用户命令的处理===========================================
:cmd
echo 请输入要执行文件的路径和文件名
set cmd=enter
set /p cmd=
if "%cmd%"=="?" goto guihelp
if "%cmd%"=="h" goto guihelp
if "%cmd%"=="H" goto guihelp
if "%cmd%"=="enter" goto command1
goto xunhuan
:command1
set cmd=c:\windows\风弛备份.bat
rem==================定义是否循环================================================
:xunhuan
echo 是否要循环运行? Y/N
set rem=enter
set /p rem=
if "%rem%"=="y" goto 14
if "%rem%"=="Y" goto 14
if "%rem%"=="enter" goto 24
if "%rem%"=="n" goto 24
if "%rem%"=="N" goto 24
:14
set rem=goto start
set yanchi=ping -n 60 127.1^>nul
goto start
:24
set rem=rem goto
cls
rem==================当前日期时间和用户输入日期时间的检测和相对处理========================
:start
if "%riqi%%time:~0,5%"=="%d% %t%" goto run
ping -n 15 127.1>nul
rem==================DOS下的帮助提示=======================================================
:help
chcp 936 >nul
echo 语法:etime 日 时间 命令(最好写完整路径) Y/N(是否循环运行,默认为N)
echo 例:etime 7 20:20 notepad.exe (7日,20:20运行 NOTEPAD这个程序,并且不循环)
echo 例:etime 7 20:20 "del c:\aaa.txt" (指定时间删除特定文件)
echo 例:etime 0 20:20 notepad.exe Y (20:20运行 NOTEPAD这个程序,并且循环)
echo DOS下输入 etime /? 或者 etime /h 得到帮助
goto exit
rem==================输入错误提示==========================================================
:warng
echo 您的日期输入有误!
echo.
goto begin
rem==================输入错误提示==========================================================
:warng1
echo 您的时间输入有误!
echo.
goto shij
rem==================执行用户定义命令或默认命令,以及是否循环==============================
:run
cls
start %cmd% :执行命令
%yanchi% :延迟时间接上文防止命令多次运行
%rem% :定义是否循环
exit :程序结束
rem==================退出到提示符下=========================================================
:warng2
echo 语法错误!!
:exit
第一天写好之后感觉一切很好,不过在经过自己的几次测试后发现了不少问题,现在把自己已知的问题都改了。目前自我感觉很好(当然老师们看了肯定会发现有很多毛病,呵呵)
附件里有我加过壳的,可以直接使用。感觉可以跟AT命令有的一拼。
Last edited by jastyg on 2006-6-12 at 16:09 ]
I haven't learned DOS myself. I'm afraid this can be attributed to the relatively late time I got in touch with computers. Fortunately, I found this great place. How happy I was~~~ And I feel that as long as I come here, I will definitely gain something!
First of all, I've been soaking in the forum for more than half a year. My level is very low, and I approach any problem with a learning attitude. But fortunately, the atmosphere of the whole forum is very good. In addition to the active attitude of the forum members, more importantly, there are a group of enthusiastic and highly skilled moderators here. They can be said to be very good teachers for us. Here, I would like to express my gratitude to the friends who have helped me.
I spent 2 days writing this small program. I mainly wanted to use what I've learned here in one go. Of course, it's a relatively low-level program. I hope you don't laugh at it and give me support.
Please let me know if there are any improper or incorrect places in my writing. I'm very willing to accept suggestions.
Change time: 2006.6.9 10:00
Spent some time in the morning adding comments, which is equivalent to checking the existing problems again by myself. Sure enough, I found a few problems. :P, the attachment hasn't been updated, and there are several problems with upper and lower cases
Change time 2006.6.12 13:00, added inspection of time and date
==========ETIME========
@echo off
color 1f
echo.
echo Scheduled Plan Tool VER:1.0
echo by: Fengchi Network, jastyg
echo Email:support@efengchi.com
echo HTTP://WWW.EFENGCHI.COM
echo for xp/2k3
echo.
echo.
rem ++++++++++++++++++++Processing in external command line mode+++++++++++++++++++++++++++
rem ===================Check if the external input is empty or is help information============
if "%1!%"=="!" goto guihelp :If the external input is empty, use the graphical page
if "%1%"=="/?" goto help :If the external input is /?, show the DOS help prompt
if "%1%"=="/h" goto help :Same as above, input /h
if "%1%"=="/H" goto help :Same as above, respectively give cases.
for %%i in (0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31) do if "%1"=="%%i" goto kaishi
goto warng2
rem====================Start setting and checking the external input==================
:kaishi
if "%1"=="0" set d=0&set riqi=0& goto t :If the initial date is 0
set /a tmp=%date:~8,3%+0 >nul :Judge if the date is the 8th or 9th, to connect with the following (method to solve invalid characters of 8 and 9)
cls :Clear screen
if errorlevel 9167 goto tmp1 :Connect with the above to accept if it is the 8th or 9th
goto tmp2
rem====================Determine the date of the 8th and 9th========================
:tmp1
echo %date:~8,2% >tem.txt :Export the current date to a temporary file
find "08" tem.txt >nul :Find whether the value 08 is contained in the temporary file, to connect with the following
if not errorlevel 1 set riqi=8&goto tmp3 :Judge if 08 is contained, then set the riqi variable to 8, jump to TMP3 label
find "09" tem.txt >nul :Find whether the value 09 is contained in the temporary file, to connect with the following
if not errorlevel 1 set riqi=9&goto tmp3 :Judge if 09 is contained, then set the riqi variable to 9, jump to TMP3 label
rem====================Processing when the external date is not 0, 8, 9===============
:tmp2
set /a riqi=%date:~8,2%+0 :Process the case where the tens digit of the date is empty to remove 0
:tmp3
set /a d=%1+0 :Process the case where the tens digit of the user input date is empty to remove 0
rem===================Process the external time and user command=================================
:t
if exist tem.txt del tem.txt :Clean up the temporary file left after setting the date
set t=%2 :Define variable T as the user input time
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,) do if "%t:~0,2%"=="%%i" goto CRC
goto warng2
:CRC
if "%t:~2,1%"==":" goto CRC1
goto warng2
:crc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto bcmd
goto warng2
:bcmd
set cmd=%~3 :Define the running program as the user input
if "%~3!"=="!" goto command :If the user doesn't input, jump to the default set value, to COMMAND
goto 4
:command
set cmd=c:\windows\Fengchi Backup.bat :Set the default running command
rem===================Set external loop option command==========================================
:4
if "%4!%"=="!" goto 41 :Judge if it is empty and jump relatively
if "%4%"=="n" goto 41 :Judge if it is lowercase n and jump relatively
if "%4%"=="N" goto 41 :Whether it is uppercase N and jump relatively
if "%4%"=="y" goto 42 :Whether it is lowercase y and jump relatively
if "%4%"=="Y" goto 42 :Whether it is uppercase Y and jump relatively
rem===================Set default and no loop==============================================
:41
set rem=echo. :Define variable as echo.
goto start :Jump to the part of checking date and time
:42
set rem=goto start :Define variable as goto statement, realize loop
set yanchi=ping -n 60 127.1^>nul :To prevent the time from running multiple times within the specified time, set a delay of 1 minute
goto start :Jump to the part of checking date and time
echo.
rem ++++++++++++++++++++Graphical setting and configuration processing++++++++++++++++++++++++++++++++++++++++
rem===================Graphical help prompt================================================
:guihelp
echo Please wait......
ping -n 1 ping 127.1 >nul
cls
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo +Usage 1: Directly run this file and follow the wizard. Enter? or h for help +
echo +Date format: For example, 9th, you can enter 9 or 09 +
echo +Time format adopts 24-hour system, that is: 20:50 (precision to minutes) +
echo +Usage 2: Command line mode; +
echo +Syntax: etime day time command (it's better to write the full path) Y/N (whether to run in loop, default is N) +
echo +Example: etime 7 20:20 notepad.exe (Run the NOTEPAD program at 20:20 on the 7th, and don't loop) +
echo +Example: etime 0 20:20 notepad.exe Y (Run the NOTEPAD program at 20:20, and loop) +
echo +Enter etime /? or etime /h in DOS to get help +
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem===================Detect and define the user input date==================================
:begin
echo Please enter date
set d1=enter :Define a value for D1, to detect if the user input is empty in the following
set /p d1= :User-defined input
if "%d1%"=="?" goto guihelp :Call graphical help
if "%d1%"=="h" goto guihelp :Same as above
if "%d1%"=="H" goto guihelp :Same as above
if "%d1%"=="enter" goto warng :Detect if the user input is empty, and process relatively
if "%d1%"=="0" set d=0&set riqi=0& goto shij :Detect if the user input is 0, and relatively define
for %%i in(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,) do if "%
d1%"=="%%i" goto 89
goto warng
:89
set /a tmp=%date:~8,3%+0 >nul :Judge if the date is the 8th or 9th, to connect with the following (method to solve invalid characters of 8 and 9)
cls
if errorlevel 9167 goto tem1 :Connect with the above to accept if it is the 8th or 9th, and jump relatively
goto tem2
rem====================Determine the date of the 8th and 9th, same as TMP1========================
:tem1
echo %date:~8,2% >tem.txt
find "08" tem.txt >nul
if not errorlevel 1 set riqi=8&goto tem3
find "09" tem.txt >nul
if not errorlevel 1 set riqi=9&goto tem3
rem====================Processing when the date is not 0, 8, 9, same as TMP2===============
:tem2
set /a riqi=%date:~8,2%+0
:tem3
set /a d=%d1%+0
rem===================Process time and user command=================================
:shij
if exist tem.txt del tem.txt :Clean up the temporary file left after setting the date
cls
echo Please enter time
set t=enter :Define a value for T, to detect if the user input is empty in the following
set /p t= :User-defined input
if "%t%"=="?" goto guihelp :Call graphical help
if "%t%"=="h" goto guihelp :Same as above
if "%t%"=="H" goto guihelp :Same as above
if "%t%"=="enter" goto warng1 :Detect if the user input is empty, and process relatively
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,?,h,H) do if "%t:~0,2%"=="%%i" goto TCRC
goto warng1
:TCRC
if "%t:~2,1%"==":" goto TCRC1
goto warng1
:tcrc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto cmd
goto warng1
rem==================Process user command===========================================
:cmd
echo Please enter the path and file name of the file to be executed
set cmd=enter
set /p cmd=
if "%cmd%"=="?" goto guihelp
if "%cmd%"=="h" goto guihelp
if "%cmd%"=="H" goto guihelp
if "%cmd%"=="enter" goto command1
goto xunhuan
:command1
set cmd=c:\windows\Fengchi Backup.bat
rem==================Define whether to loop================================================
:xunhuan
echo Whether to run in loop? Y/N
set rem=enter
set /p rem=
if "%rem%"=="y" goto 14
if "%rem%"=="Y" goto 14
if "%rem%"=="enter" goto 24
if "%rem%"=="n" goto 24
if "%rem%"=="N" goto 24
:14
set rem=goto start
set yanchi=ping -n 60 127.1^>nul
goto start
:24
set rem=rem goto
cls
rem==================Detection and relative processing of current date time and user input date time========================
:start
if "%riqi%%time:~0,5%"=="%d% %t%" goto run
ping -n 15 127.1>nul
rem==================DOS help prompt=======================================================
:help
chcp 936 >nul
echo Syntax: etime day time command (it's better to write the full path) Y/N (whether to run in loop, default is N)
echo Example: etime 7 20:20 notepad.exe (Run the NOTEPAD program at 20:20 on the 7th, and don't loop)
echo Example: etime 7 20:20 "del c:\aaa.txt" (Delete a specific file at the specified time)
echo Example: etime 0 20:20 notepad.exe Y (Run the NOTEPAD program at 20:20, and loop)
echo Enter etime /? or etime /h in DOS to get help
goto exit
rem==================Input error prompt==========================================================
:warng
echo Your date input is incorrect!
echo.
goto begin
rem==================Input error prompt==========================================================
:warng1
echo Your time input is incorrect!
echo.
goto shij
rem==================Execute user-defined command or default command, and whether to loop==============================
:run
cls
start %cmd% :Execute command
%yanchi% :Delay time connects with the above to prevent multiple runs of the command
%rem% :Define whether to loop
exit :Program ends
rem==================Exit to the prompt=========================================================
:warng2
echo Syntax error!!
:exit
After writing it on the first day, I felt everything was fine. But after several tests by myself, I found many problems. Now I've changed all the problems I know. Currently, I feel very good (of course, the teachers will definitely find many flaws when they see it, hehe)
There is the one I added a shell to in the attachment, which can be used directly. It feels comparable to the AT command.
Last edited by jastyg on 2006-6-12 at 16:09 ]
附件
1: etime.rar (2006-6-12 16:08, 63.43 KiB, 下载附件所需积分 1 点
,下载次数: 104)
|
|
2006-6-8 19:20 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
把你的代码copy下来试运行了一下,初步发现了如下几个问题:
1、每一步操作只有输入提示,而没有该输入的功能解释,让人不知道输入之后将执行什么操作;建议对每一步操作作功能提示;
2、不知道该输入什么命令查看你的帮助内容;即使输入/? /help等你指定的命令,但运行的是另外的功能;建议修改代码;
3、@echo off之后的命令没必要再次用@来隐藏;建议删除重复的@以精简代码;
4、代码中,标号的命名一会用英文,一会用拼音,比较混乱;各部分的功能有的甚至用数字来表示,让人难以一下子明白该标号下的内容是什么功能;建议对标号统一命名,最好是能够见名知义;
5、输入部分没有错误检测,如果输入有误,程序运行时有可能发生意外;建议对输入部分作错误检测;
6、设置变量的时候,用到了rem、tmp等有特定含义的变量,个人觉得会对CMD环境产生影响(没有作进一步验证,有待各位达人给出权威结论),建议用另外的字符替换它们;
呵呵,一口气说了你的代码一大堆缺点,希望别介意。
本人正在完善一个文件备份脚本程序,希望你能关注一下,其中部分代码对你完善这个脚本会有所帮助,同时,也希望你能对我的脚本提一些建议。
下面是我的脚本在本论坛的地址:
文件备份器: http://www.cn-dos.net/forum/viewthread.php?tid=20747&fpage=0&highlight=&page=1
Last edited by namejm on 2006-6-8 at 20:30 ]
I copied and ran your code for a trial run, and initially found the following problems:
1. Each step of operation only has input prompts, but no functional explanations of the input, making it unclear what operation will be executed after input; it is suggested to provide functional prompts for each step of operation;
2. I don't know what command to input to view your help content; even if I input the specified commands such as /? /help, other functions are run; it is suggested to modify the code;
3. There is no need to use @ again to hide the commands after @echo off; it is suggested to delete the duplicate @ to streamline the code;
4. In the code, the naming of labels is sometimes in English and sometimes in pinyin, which is relatively chaotic; the functions of each part are even sometimes represented by numbers, making it difficult to immediately understand what function the content under the label is; it is suggested to unify the naming of labels, preferably so that the name can indicate the meaning;
5. There is no error detection in the input part, and if the input is wrong, the program may have accidents during operation; it is suggested to perform error detection on the input part;
6. When setting variables, variables with specific meanings such as rem, tmp are used, and I personally think it may have an impact on the CMD environment (no further verification has been done, and authoritative conclusions are awaited from various experts); it is suggested to replace them with other characters;
Hehe, I just talked a lot about the shortcomings of your code, hope you don't mind.
I am currently improving a file backup script program, and hope you can pay attention to it. Part of the code will be helpful for you to improve this script, and at the same time, I hope you can give some suggestions on my script.
The following is the address of my script in this forum:
File Backup Tool: http://www.cn-dos.net/forum/viewthread.php?tid=20747&fpage=0&highlight=&page=1
Last edited by namejm on 2006-6-8 at 20:30 ]
|
|
2006-6-8 20:17 |
|
|
jastyg
中级用户
  
积分 219
发帖 82
注册 2005-10-29
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
1、每一步操作只有输入提示,而没有该输入的功能解释,让人不知道输入之后将执行什么操作;建议对每一步操作作功能提示;
这个我觉的没必要详细解释。只需要跟向导走应该没问题的。
2、不知道该输入什么命令查看你的帮助内容;即使输入/? /help等你指定的命令,但运行的是另外的功能;建议修改代码;
我这边在XP/2K3下 输入 etime /? or etime /h是可以查看的,不知道你的是什么系统?2000由于没有环境,所以我测试不了。
3、@echo off之后的命令没必要再次用@来隐藏;建议删除重复的@以精简代码;本人愚昧没发现有多余的,请明确指出,谢谢
4、代码中,标号的命名一会用英文,一会用拼音,比较混乱;各部分的功能有的甚至用数字来表示,让人难以一下子明白该标号下的内容是什么功能;建议对标号统一命名,最好是能够见名知义;
这个是因为当时自己设计的时候没想的很周全,导致测试的时候问题多多,没办法才这样,修修补补的。呵呵
5、输入部分没有错误检测,如果输入有误,程序运行时有可能发生意外;建议对输入部分作错误检测;
做了简单的输入检测,我想要求你输入日的时候,最常见的是输入比如,7号那天的话,一般是07 OR 7。想不到难道使用者会输入为70?
6、设置变量的时候,用到了rem、tmp等有特定含义的变量,个人觉得会对CMD环境产生影响(没有作进一步验证,有待各位达人给出权威结论),建议用另外的字符替换它们;
这个确实是个缺陷,谢谢兄的明确指出,不过还好我目前测试还没到影响使用的地步
谢谢你提出的宝贵意见,在学习的过程中难免会出现很多问题,你的意见我会接受的。
1. Each step of the operation only has input prompts, but no functional explanations for the input, making it unclear what operation will be performed after input; it is suggested to provide functional prompts for each step of the operation;
I think this is not necessary to explain in detail. It should be okay to just follow the guide.
2. Don't know what command to enter to view your help content; even if entering the specified commands like /? /help, other functions are run; it is suggested to modify the code;
Here, under XP/2K3, entering etime /? or etime /h can be viewed. I don't know what system you have? 2000 has no environment, so I can't test it.
3. The @echo off command doesn't need to use @ again to hide the subsequent commands; it is suggested to delete the duplicate @ to streamline the code; I am ignorant and didn't find the excess, please point it out clearly, thank you
4. In the code, the labeling is sometimes in English and sometimes in pinyin, which is relatively chaotic; the functions of each part are even sometimes represented by numbers, making it difficult to immediately understand what function is under this label; it is suggested to unify the labeling, preferably so that the meaning can be known from the name;
This is because I didn't think very comprehensively when designing it at that time, resulting in many problems during testing, and I had to make do. Hehe
5. There is no error detection in the input part, and if the input is wrong, the program may have accidents during operation; it is suggested to perform error detection on the input part;
Simple input detection has been done. I think when asking you to enter the day, the most common is to enter, for example, on the 7th, generally 07 OR 7. I can't imagine that the user would enter 70?
6. When setting variables, rem, tmp and other variables with specific meanings are used. Personally, I think it will affect the CMD environment (no further verification has been done, waiting for experts to give authoritative conclusions), it is suggested to replace them with other characters;
This is indeed a defect. Thank you for clearly pointing it out. But fortunately, my current test hasn't reached the point of affecting use yet
Thank you for your valuable suggestions. Many problems are inevitable during the learning process, and I will accept your suggestions.
|
|
2006-6-8 20:43 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Re jastyg:
还在揣摩兄的脚本是如何运作的:)
按照一般人使用bat程序的习惯,一般是双击该脚本来运行的,没有谁会先打开cmd窗口,然后再输入bat程序的完整路径来运行吧?所以说,应该在双击bat后打开的第一个界面中,就应该有该程序的功能介绍,或者是提示输入某条命令或某个字符查看该脚本的帮助内容。正是因为这个习惯问题,所以当双击这个脚本来运行的时候,就直接输入/?希望能查看你这个脚本的帮助,结果跳出了不相关的帮助内容,几乎让我怀疑我的CMD神经错乱了呢:)
@echo off之后的@color 1f一句中,可把@去掉。
关于错误检测一节,我的意见是这样的:如果在输入的时候,不小心直接就按了回车,也就是说输入为空的时候,运行会出意外——你不能保证别人什么时候都会正确地输入吧?还有其他输入出错的情况,请多为粗心的用户考虑一下吧。另外一种情况:在你这个代码中,输入时间一项没有作说明就很有问题,到底应该输入时间的整点数呢,还是输入带冒号的格式?要不要精确到秒?……
因为批处理中,rem起注释的作用,%tmp%引用的是临时文件目录,把它们设置为变量在你目前这个脚本中没有什么问题,但是,还是建议不要用把批处理的命令或者系统环境变量设置为变量,以免在代码量大的情况下,引用得晕头转向的时候出错。良好的代码编写习惯是写出正确代码的一大保证,你说呢?
如果要追求完美,还有很多地方值得完善:比如,可考虑去掉CMD窗口的下拉条,以防止新手乱拉后找不到有内容的位置。
嘿嘿,老挑你毛病,再次希望别介意。
Re jastyg:
Still pondering how your script works : )
According to the general habit of people using bat programs, usually they double-click the script to run it. No one would open the cmd window first and then enter the full path of the bat program to run it. So, in the first interface that opens after double-clicking the bat, there should have the function introduction of the program, or prompt to enter a certain command or character to view the help content of the script. It is precisely because of this habit issue that when double-clicking the script to run, directly entering /? to view the help of your script results in irrelevant help content, almost making me doubt if my CMD is malfunctioning : )
In the line @color 1f after @echo off, the @ can be removed.
Regarding the error detection section, my opinion is like this: If when entering, you accidentally just press Enter, that is, when the input is empty, the operation will have an accident - you can't guarantee that others will input correctly all the time. There are other situations of input errors, so please consider more for careless users. Another situation: In your code, the time entry is very problematic without explanation. Exactly, should you enter the integer point of time, or the format with colons? Should it be precise to seconds?...
Because in batch processing, rem is for comments, and %tmp% refers to the temporary file directory. Setting them as variables is okay in your current script, but it is still recommended not to set batch processing commands or system environment variables as variables, so as to avoid mistakes when getting confused when referencing with a large amount of code. Good code writing habits are a great guarantee for writing correct code, what do you think?
If you want to pursue perfection, there are many places worth improving: for example, consider removing the drop-down bar of the CMD window to prevent novices from getting lost in the content after randomly pulling it.
Hehe, always picking on your flaws, hope you don't mind again.
|
|
2006-6-8 21:48 |
|
|
jastyg
中级用户
  
积分 219
发帖 82
注册 2005-10-29
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
re: namejm
兄说的很有道理,可能是自己没写过程序,考虑的真的是很不周到。
@color 1f一句中的@是自己的一时疏忽,因为程序测试的时候问题多多啊,所以就直接在第一行加了:@echo off,以便于测试。关于输入为空,我已经想到怎么做了,谢谢兄的提醒。对于说明确实是应该加在程序的开始,这样更明了。时间的格式是20:05这样的。
兄对我提出的意见使我收益颇深啊,我的原意也是这样的,把自己写的放出来给大家看,希望得到的就是提出我的不足啊。很是感谢你。
兄的贴我刚才也看了,佩服你的耐心和水平,你的贴我是没看完,一来没耐心,二者很多地方看不懂,见笑了~~~~
re: namejm
Brother's statement makes a lot of sense. Maybe it's because I haven't written a program myself, and I really didn't think through things very comprehensively.
In the line @color 1f, the @ was a momentary oversight of mine. Because there were many problems during the program testing, so I directly added @echo off in the first line for easier testing. Regarding the empty input, I have already thought about how to handle it, thank you for the reminder. The instructions really should be added at the beginning of the program for clearer understanding. The time format is like 20:05.
Brother's suggestions to me have benefited me a lot. My original intention was also to release what I wrote for everyone to see, and what I hope to get is to have my deficiencies pointed out. I'm really grateful to you.
I just read brother's post, and I admire your patience and level. I didn't finish reading your post. For one thing, I don't have patience, and for another, I don't understand many places. Please forgive me~~~~
|
|
2006-6-8 22:08 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
说到我的水平,其实看我的注册时间就可以看出来了;再有,我目前的工作和计算机领域相隔十万八千里,在外人看来很难把两者联系起来。只是自己对电脑很感兴趣,所以就在坛子里泡上了:)在论坛里学到了很多东西,真的很感谢这里的众多高手。呵呵,似乎扯远了点。
嘿嘿,我又要挑你的毛病了哈——好象专门和你过不去,你可别拿板砖砸我呀。
goto kaishi和:kaishi这两句,因为是紧跟在一起的,按照bat命令的执行顺序,是自上而下执行的(跳转除外),所以goto kaishi一句可省略;
if "%1"=="0" set d=0&set riqi=0& goto t一句中,set d=0和set riqi=0可省略,CMD中不用初始化变量值的(呵呵,CMD里有“初始化”的说法吗?我也不是很懂,姑且这么叫吧),当然,这样做也没有运行出错;(后来参考了其他帖子,发现这段言论是错误的,设置初始值为0是有必要的)
set /a tmp=%date:~8,3%+0 >nul这句中+0起什么作用?
if errorlevel 9167 goto tmp1一句中,错误码9167是什么含义?是判断操作系统版本语句吗?看不太明白,请兄解释一下;
echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3 这几句看不太明白:为什么要查找"08"这个字符?起什么作用?
在每次输入完毕之后,建议用cls命令清屏,不要让上一次的输入保留在屏幕上。
另外,感觉你写代码的时候,逻辑理得不是很顺,建议用以下顺序把代码串起来:先按照正确输入时的情况把每一步骤的代码写在一起,然后再把有分支流向的代码写在一堆,最后再把各种错误检测代码放在一块,以标号分割的每一节代码最好加上注释,表明本节的功能,觉得重要的地方也可以考虑添加注释。如果这样做的话,就会让人很快就看出你写的代码的逻辑结构,不仅方便自己以后完善代码时快速找到位置,也能让别人很快看出你的错误出在哪里。
由于自己的水平有限,目前只提出了如上几个问题,更多可完善之处,还需要大家来发现。
Last edited by namejm on 2006-6-9 at 00:36 ]
Regarding my level, actually you can tell from my registration time; also, my current job is far removed from the computer field, and it's hard for outsiders to connect the two. It's just that I'm very interested in computers, so I've been lurking in the forum :) I've learned a lot here, and I really thank the many experts here. Hehe, it seems I've strayed a bit.
Hehe, I'm going to pick on your faults again ha—It seems like I'm specifically picking on you, don't throw bricks at me.
The two lines goto kaishi and :kaishi, since they are right next to each other, according to the execution order of bat commands, which is top-to-bottom execution (except for jumps), so the goto kaishi line can be omitted;
In the line if "%1"=="0" set d=0&set riqi=0& goto t, the set d=0 and set riqi=0 can be omitted. In CMD, there's no need to initialize variable values (hehe, is there such a saying as "initialization" in CMD? I'm not very懂 either, I'll call it that for now). Of course, doing this also doesn't cause errors in running;(Later, referring to other posts, I found that this statement is wrong. Setting the initial value to 0 is necessary)
What's the role of +0 in the line set /a tmp=%date:~8,3%+0 >nul?
What's the meaning of the error code 9167 in the line if errorlevel 9167 goto tmp1? Is it a statement to judge the operating system version? I don't understand very well, please explain;
The几句 echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3 are not very understandable: Why look for the character "08"? What's the role?
After each input is completed, it's recommended to use the cls command to clear the screen, don't let the previous input remain on the screen.
Also, I feel that when you write the code, the logic isn't very smooth. It's recommended to string the code in the following order: first write the code for each step when input is correct together, then put the code with branch flows together, and finally put all the error detection codes together. Each section of code labeled with a label should preferably have comments to indicate the function of this section, and you can consider adding comments where important. If you do this, it will make it very easy for people to see the logical structure of the code you wrote. It's not only convenient for you to quickly find the position when improving the code later, but also makes it easy for others to see where the errors are.
Due to my limited level, I've only raised the above few questions for now. There are more areas that can be improved, and everyone needs to discover them.
Last edited by namejm on 2006-6-9 at 00:36 ]
|
|
2006-6-8 23:05 |
|
|
jastyg
中级用户
  
积分 219
发帖 82
注册 2005-10-29
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
re: namejm
根据兄的提示,我已经做了部分修改,大批量的改自己也眼花,呵呵!
set /a tmp=%date:~8,3%+0 >nul这句中+0起什么作用?
这个其实我也是没办法,兄要仔细看一下SET/?就会得到08,09是无效的数字,因为8,9不是有效的8进制位数。
所以运行上面的代码就会出错。通过 echo %errorlevel %得到 errorlevel =9167。
因为8,9是无效的,所以如果输入日期为8,9的时候我的程序就不可能正确(PS:昨天是7号,我测试好的,今天就不行,后来才发现是这个问题,而且是除了8,9其他都没问题)
echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3
通过把指定的日期里显示日的字符导出到TEM。TXT里然后查找,如果有8,就设置%riqi%=8(也就是8号),同理得到9号。
因为我是通过if "%riqi%%time:~0,5%"=="%d%%t%" goto run来确定数值是否一致的。
确实逻辑性是差多了,见笑了,呵呵。能用知足~~~。
有了这次的经验以后应该要好的多了~~
多谢兄的耐心指点
不早了,早点休息。明天继续盼兄回复~~~
PS:自己也发现了还有些问题不足,明天想办法看能不能解决,比如用户误输入特殊符号之类的,还望兄给出好的思路。
Last edited by jastyg on 2006-6-8 at 23:40 ]
re: namejm
According to your hint, I have made some modifications. It's really tiring to make large-scale changes, heh heh!
What's the function of +0 in the sentence set /a tmp=%date:~8,3%+0 >nul?
Actually, I have no choice. You should carefully look at SET/? and you will get 08, 09 are invalid numbers because 8 and 9 are not valid octal digits.
So running the above code will cause an error. By echo %errorlevel % we get errorlevel =9167.
Because 8 and 9 are invalid, so if the input date is 8 or 9, my program can't be correct (PS: yesterday was the 7th, I tested it well, but today it's not working, and then I found this problem, and it's okay except for 8 and 9)
echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3
By exporting the characters showing the day in the specified date to TEM.TXT and then searching, if there is 8, set %riqi%=8 (that is, the 8th), and similarly get the 9th.
Because I determine whether the values are consistent by if "%riqi%%time:~0,5%"=="%d%%t%", so I go to run.
Indeed, the logic is much worse, please forgive me, heh heh. It's enough to be able to use it~~~.
With this experience, it should be much better in the future~~
Thanks for your patient guidance
It's getting late, go to bed early. Looking forward to your reply tomorrow~~~
PS: I also found that there are still some problems and deficiencies. I want to see if I can solve them tomorrow, such as users mistakenly entering special symbols, etc. I hope you can give good ideas.
Last edited by jastyg on 2006-6-8 at 23:40 ]
|
|
2006-6-8 23:34 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
比起我那个文件备份器700多行的代码来说(不过很多是rem和echo语句,是我故意夸张的说法),你这100多行的代码量算小的了,但是我依然能很快找到问题出在哪一句,正是得益于自己最开始的时候把逻辑顺序理得比较顺了(不敢说是最好的逻辑顺序),但愿你也能弄一个方便自己修改的顺序出来。
关于输入错误检测,在我那个文件备份器的帖子里讨论得比较多,你花点时间慢慢看就会明白的。
给你个建议:写代码的时候,尽量少产生临时文件,如果要产生临时文件,多想想能不能用for语句及&、&&、|和||等连接符来避免临时文件。
还不能很好地领会你的代码,但是直觉告诉我,set /a tmp=%date:~8,3%+0 >nul一句对8和9这两个数应该有更简洁的处理办法,嘿嘿,问问willsort老大,他应该有办法的。
Compared with the more than 700 lines of code in my file backup tool (but many are rem and echo statements, which is an exaggerated statement I made on purpose), your code with more than 100 lines is considered small. But I can still quickly find out where the problem is, which is precisely due to the fact that I sorted out the logical order relatively well at the very beginning (I don't dare to say it's the best logical order). I hope you can also come up with an order that is convenient for your own modification.
Regarding input error detection, it has been discussed a lot in my post about the file backup tool. Just take your time to read it and you will understand.
Here's a suggestion for you: when writing code, try to generate as few temporary files as possible. If you have to generate temporary files, think more about whether you can use the for statement and connectors such as &, &&, |, and || to avoid temporary files.
I still can't fully understand your code, but my intuition tells me that there should be a more concise way to handle the numbers 8 and 9 in the statement set /a tmp=%date:~8,3%+0 >nul. Hehe, ask Boss willsort, he should have a way.
|
|
2006-6-9 00:00 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
to jastyg:
版主给你的帖子划红杠杠啦,你可要加油哇,争取弄上置顶或者精华:P
俺睡觉去也~~~~~
to jastyg:
The moderator has marked your post with a red line. You need to work hard and strive to get it pinned or made an essence. ????
I'm going to sleep now~~~~~
|
|
2006-6-9 00:55 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Re jastyg:
首先,“原创”代码都是值得赞赏和鼓励的,这是我将此主题红色下划线高亮的决定性考量。
其次,此主题存在许多技术性细节可以探讨,所以它具有成为精华主题的潜质;当然,在此之前我们首先需要对主题中的代码进行初步的完善,即 namejm 兄所提到的框架逻辑的改善,主要包括每个模块的功能相对独立,标签名清晰易懂,同时有适当的空行作为间距。
再次,建议你的代码发布方式参考 namejm 兄的原创主题,新的代码将不断更新在主题的首帖中,并在主题标题中标明变化的版本号和更新日期。另外,建议你转贴代码时,在代码前后使用[code]和[/code],这样可以防止代码中的某些特殊字符被转义,便于浏览和复制,同时凸现代码的特殊性。
最后,关于 namejm 兄交给我的 08/09 问题,我是这样考虑的。之所以会出现 08/09 被识别为八进制数的问题,是因为使用了set/a命令,而我观察了代码中出现的所有set/a语句,都只是将日期值加零,而我看不出它有什么实际的意义。或许,你是想实现日期字符串向整型数值的转换,但这在批处理中是不需要实现也很难实现的,所有会处理整数的命令行程序都会自行将字符串数字转换为整型数值,因为这是命令行环境所固有的约定。
当然,08/09问题可以更简单地解决,如果你确实需要对日期值进行set/a运算,我可以提供相应的方案。
[[i] Last edited by willsort on 2006-6-9 at 02:18 [/i]]
Re jastyg:
First of all, "original" code is worthy of appreciation and encouragement, which is the decisive consideration for me to highlight this topic with a red underline.
Secondly, there are many technical details in this topic that can be discussed, so it has the potential to become an essence topic; of course, before that, we first need to initially improve the code in the topic, that is, the framework logic improvement mentioned by Brother namejm, mainly including the relatively independent function of each module, clear and easy-to-understand tag names, and appropriate blank lines as spacing.
Again, it is suggested that your code release method refer to Brother namejm's original topic. The new code will be continuously updated in the first post of the topic, and the changed version number and update date will be marked in the topic title. In addition, it is suggested that when you repost the code, use and
before and after the code, so as to prevent some special characters in the code from being escaped, which is convenient for browsing and copying, and at the same time highlight the particularity of the code.
Finally, regarding the 08/09 problem handed over to me by Brother namejm, this is my consideration. The reason why 08/09 is recognized as an octal number is because the set/a command is used, and I have observed all the set/a statements in the code, which only add zero to the date value, and I can't see what practical meaning it has. Maybe you want to realize the conversion of the date string to an integer value, but this is not needed and difficult to realize in batch processing. All command line programs that can handle integers will automatically convert the string number to an integer value by themselves, because this is an inherent convention in the command line environment.
Of course, the 08/09 problem can be solved more simply. If you really need to perform set/a operation on the date value, I can provide corresponding solutions.
Last edited by willsort on 2006-6-9 at 02:18 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-9 02:13 |
|
|
jastyg
中级用户
  
积分 219
发帖 82
注册 2005-10-29
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
re: namejm
限于能力的问题,有的其实我想做,但做不了,正如您所说的用FOR等语句,但是我对这方面了解的不深入,当然也看了不少这方面的帖,真的感觉深了点,呵呵。慢慢来~~
re:willsort
首先谢谢斑竹对我多次的帮助,关于SET/A我是这样理解并这样做的,由于我在取日期这个值的时候存在这样的问题,比如单号的时间1-9号,但我取值必须要取2个字符的值否则等到双号的就出错了,即这样比如是7号的话,取到的值为:07,如果当我指定的时间输入为7的话,则两边不等,语句将执行错误,所以我通过取得当前日期的时候通过+0使得为十位数去空,同理,也给用户输入的日期做了去十位空的处理,这样语句能顺利运行。
当然,很乐意斑竹能给出更好的方案。
我会尽量抽点时间出来给上面做个批注(呵呵,我自己看的都有点乱,如果不是自己写的真没耐心看下去了)
PS:世界杯到了,又是折磨人的日子啊~~~
Last edited by jastyg on 2006-6-9 at 21:40 ]
re: namejm
Due to the limitations of my ability, there are actually things I want to do but can't. As you said, using statements like FOR, but I don't have an in-depth understanding of this aspect. Of course, I have also read quite a few posts on this topic, and I really find it a bit deep, heh heh. Take it slow~~
re: willsort
First of all, thank you, moderator, for helping me many times. Regarding SET/A, this is how I understand and do it. Because when I get the date value, there is such a problem. For example, the order number is from the 1st to the 9th, but I have to get a 2-character value, otherwise it will be wrong when it comes to the even-numbered days. That is, for example, if it is the 7th, the value obtained is: 07. If the time I specified is entered as 7, then the two sides are not equal, and the statement will execute incorrectly. So I make the current date +0 to make it a ten-digit number to remove the space. Similarly, I have also processed the user-entered date to remove the ten-digit space, so that the statement can run smoothly.
Of course, I am very willing for the moderator to give a better solution.
I will try to take some time to add comments to the above (heh heh, I myself find it a bit confusing, if it weren't written by myself, I really wouldn't have the patience to read it)
PS: The World Cup is here, another torturous day~~~
Last edited by jastyg on 2006-6-9 at 21:40 ]
|
|
2006-6-9 08:51 |
|
|
jastyg
中级用户
  
积分 219
发帖 82
注册 2005-10-29
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
关于非法字符的检验我相出了一个方法,但感觉有点烦琐,先贴出来:
@echo off
set /p da=
for %%i in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,/?,/h,/H) do if "%da%"=="%%i" goto ok
goto warng
:ok
echo ok
goto exit
:warng
echo 错误
:exit
这样对日期的检测确实可以,但时间格式的检验呢?
Regarding the verification of illegal characters, I came up with a method, but it feels a bit cumbersome. Let me post it first:
@echo off
set /p da=
for %%i in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,/?,/h,/H) do if "%da%"=="%%i" goto ok
goto warng
:ok
echo ok
goto exit
:warng
echo Error
:exit
This can indeed detect the date, but what about the verification of the time format?
|
|
2006-6-9 11:32 |
|
|
jastyg
中级用户
  
积分 219
发帖 82
注册 2005-10-29
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
对于时间的检测,想到一个愚昧的方法
把用户输入的时间分段进行日期一样的检验。
不知道有没更好的方法?
For the detection of time, I thought of a stupid method
Check the user-entered time in segments for the same date.
I wonder if there is a better way?
|
|
2006-6-9 11:55 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Re jastyg:
从11楼回复中理解了兄使用 set/a 的意图,即将日期值可能含有的零前缀剔除,使之有统一的格式以便于比较。
嗯,这个问题可以从两方面来看:
1、所有的日期都保证它含有可能的零前缀,这样可以进行比较。因为系统日期通常都具有可能的零前缀,所以我们通常只需要负责用户输入的日期变量即可。而具体采用的将是先补齐再截取的方案,比如:
set today=%date:~8,2%
set /p day=请输入日期:
set day=0%day%
set day=%day:~-2%
echo 输入的日期:%day%;系统的日期:%today%;
2、所有的日期都保证它不含有可能的零前缀,这样也可以进行比较。因为系统日期通常都具有可能的零前缀,所以我们需要同时负责用户输入的日期值和系统的日期值。这里我们采用先加10000或1000然后再求余的办法。比如
set today=%date:~8,2%
set /p day=请输入日期:
set /a today=100%today% %% 100, day=100%day% %% 100
echo 输入的日期:%day%;系统的日期:%today%;
Re jastyg:
Understood the intention of the brother using set/a from the reply on floor 11, which is to remove the possible leading zeros in the date value to have a unified format for easy comparison.
Well, this problem can be viewed from two aspects:
1. Ensure all dates have possible leading zeros so that they can be compared. Because the system date usually has possible leading zeros, so we usually only need to handle the user-input date variable. The specific plan to be adopted is to pad first and then intercept, for example:
set today=%date:~8,2%
set /p day=Please enter the date:
set day=0%day%
set day=%day:~-2%
echo Input date: %day%; System date: %today%;
2. Ensure all dates do not have possible leading zeros so that they can also be compared. Because the system date usually has possible leading zeros, so we need to handle both the user-input date value and the system date value. Here we use the method of adding 10000 or 1000 first and then taking the remainder. For example
set today=%date:~8,2%
set /p day=Please enter the date:
set /a today=100%today% %% 100, day=100%day% %% 100
echo Input date: %day%; System date: %today%;
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-9 17:58 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
老大的办法还真多哈,挺巧妙的。
to jastyg:
其实没必要注释这么多内容,注释多了反倒有累赘感。
再有,在帖代码的时候,你可以用这个方法,以保证某些字符不被网页转换掉,同时也方便别人复制你的代码作测试之用:先输入 [code] 和 [/code] ,然后在两者之间粘贴代码,然后发表就成了,其实挺简单的。最好是用“回复”模式来编辑,里面有更多的格式可供选择;“快速回复主题”模式可供选择的格式几乎没有,对网页代码比较熟悉的可以在此手工输入代码来编辑,如果你不熟悉的话,建议还是采用“回复”模式来弄吧。
[[i] Last edited by namejm on 2006-6-9 at 19:16 [/i]]
The boss really has many ways, quite clever.
To jastyg:
Actually, there's no need to comment so much content. Too many comments will反而 have a sense of redundancy.
Moreover, when posting code, you can use this method to ensure that certain characters are not converted by the webpage and also facilitate others to copy your code for testing purposes: first input and
, then paste the code between them, and then post it. Actually, it's quite simple. It's best to use the "Reply" mode to edit, as there are more formats available; the "Quick Reply to Topic" mode has almost no formats available. Those familiar with webpage code can manually input code here to edit. If you are not familiar, it is recommended to still use the "Reply" mode to do it.
Last edited by namejm on 2006-6-9 at 19:16 ]
|
|
2006-6-9 19:14 |
|
|