12 Aug
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