Damon 涂鸦天地 |

CAT | 编程

Aug/07

12

常用DOS批处理命令

 PS:网上找到的不错的批处理例子。但有些不适合在XP下使用了,我做了点小修改。没改全部的。

接收键盘输入字符串的程序

:: Get user input – includes error check
@echo off
echo e102′set %%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.|date /t>sysdate.bat
echo.|time /t>systime.bat
rem 修改系统时间为指定时间,日期为参数一,时间为参数二,文件名为参数三
date %1
time %2
rem 修改文件的时间
copy %3+,,>nul
rem 恢复系统时间
echo date %%4>current.bat
call sysdate
echo time %%3>current.bat
call systime
rem 程序执行完毕
echo Success.
del systime.bat
del sysdate.bat
del current.bat
echo on

(阅读全文……)

No tags

Theme Design by devolux.nh2.me
Blog WebMastered by All in One Webmaster.

Featuring WPMU Bloglist Widget by YD