文档详情

精彩批处理代码.pdf

发布:2017-05-18约6.54千字共9页下载文档
文本预览下载声明
精彩批处理代码 接收键盘输入字符串的程序 ::Get user input - includes error check @echo off echo e102set %%1 %temp%.\t1.dat for %%? in (w q) do echo %%? %temp%.\t1.dat :input echo. echo Type input: FC con nul /lb1 /n |FIND 1: %temp%.\t2.bat ::Error checking begins here FIND | %temp%.\t2.bat nul if not errorlevel 1 goto error FIND %temp%.\t2.bat nul if not errorlevel 1 goto error FIND nul if not errorlevel 1 goto error FIND %temp%.\t2.bat nul if not errorlevel 1 goto error ::Error checking end DEBUG %temp%.\t2.bat nul call %temp%.\t2.bat 字符串 for %%? in (t1.dat t2.bat) do del %temp%.\%%? echo 字符串 %字符串% goto eof :error echo. echo @PROMPT Invalid input. Invalid characters:$Q $L $G $B$_ %temp%.\t2.bat %comspec% /c %temp%.\t2.bat |FIND : goto input :eof 一个修改文件的更新日期的程序 @echo off rem 保存系统时间 echo.|datesysdate.bat echo.|timesystime.bat rem 修改系统时间为指定时间,日期为参数一,时间为参数二,文件名为参数三 date %1 time %2 rem 修改文件的时间 copy %3+,,nul rem 恢复系统时间 echo date %%4current.bat call sysdate echo time %%3current.bat call systime rem 程序执行完毕 echo Success. del systime.bat del sysdate.bat del current.bat echo on PING某个区段内的所有IP 的程序 在命令行输入 a.bat 0 1 2 3 4 5 6 7 8 9 ,就能显示某区段的所有 IP 地址 -9 ,将其中的 echo 改成 ping 就行,其中的 choice 和 if 语句是等待用户判断是否继续,可以删除,但这样中断程序比较麻烦。 CODE: [Copy to clipboard] @echo off :redo if %1 goto end for %%a in (0,1,2,3,4,5,6,7,8,9) do echo 192.168.1.%1%%a choice continue if errorlevel 2 goto end shift goto redo :end 一个定时器程序 程序中的 CURRENT.BAT 可以更换为自己需要执行的内容。FIND 一句的时间可以根据自 己的需要设定,也可用参数%1代替。还可以改为 TIME 改为 DATE 以完成的定期执行的 功能。 Quote: ::CURRENT.BAT @echo off echo Haha, its the time to go!! ::TIMER.BAT @echo off :start echo.|time|find 10:30:00run.bat choice /c:y /t:y,59 /nnul call run.bat goto start ASCII汇编代码,延迟精度为0.001秒,适用平台为MS-DOS/Win9x/WinNT。 德国人Herbert Kleebauer给出了一个通用方案,通过ASCII汇编器间接产生一个 sleep.exe程序来实现延迟,这个程序分为DOS和Win两个模块,分别调用DOS系统中 断服务和WindowsAPI。 CODE: [Copy to clipboard] :: Sleep.bat - Sleep/Delay/Wait n sec
显示全部
相似文档