作者: Roy 时间: 2003-7-23 00:00 :: 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
作者: hzy 时间: 2003-7-23 00:00 谢谢斑竹!可是我看了还是不太懂!作者: GOTOmsdos 时间: 2003-8-18 00:00 首先我觉得批处理的手段一般来说达不到问者的这个要求(否则要编一个复杂的脚本),能不能灵活处理一下,比如,要用"%wer%"变量就得预先设好([除了在自动批处理autoexec.bat中和在配置文件config.sys中之外],还可当场在屏幕中输入"set wer=dfhgire.txt",这是不是满足了问者要在屏幕输入字符串的要求?),
要不然问者的要求是:在屏幕输入仅仅这个"变量名"(wer),这跟批处理的"%--%"变量的用法矛盾.
其实,还有一种变量可以符合问者的基本意图: %1-%9
写成批处理: for %a in (c: d: e: f: g: h do dir /b /s %a\%1
然后在屏幕输入dfhgire.txt
这样是不是基本满足问者的要求? 作者: willsort 时间: 2003-9-6 00:00 Re hzy: