![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-01 23:19 |
共 48,037 主题排行 / 350,122 发帖 / 今日 2 篇 / 48,250 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » 能否在批处理中用CHOICE动态选择(windows 9x环境) |
| 可打印版本 1,259 / 6 |
| 第1楼 BAT | 发表于 2006-08-15 22:40 |
| 初级用户 发帖 52 积分 177 | |
|
能否在批处理中用CHOICE动态选择(windows 9x环境) 想在批处理实现一个动态显示与选择,搜索C盘根目录是否存在符合要求的文件夹,如果存在两个符合要求的文件夹,则choice /c12
如果存在三个符合要求的文件夹,则choice/c123 如果存在四个符合要求的文件夹,则choice/c1234 提示信息用ECHO 变量来实现, 例如判断C盘是否存在 a,b,c,d,e,f,g,l目录,如果存在a,b则显示a,b存在于C盘,并CHOICE/C12 如果存在a,d,e则显示a,d,e于C盘,并choice/c123 下面需要对符合条件的目录进行一定的操作, 小弟一直想不出一个完整的解决思路,恳请各位兄弟提供解决的思路,谢谢之 [ Last edited by BAT on 2006-8-15 at 22:44 ] |
|
| 第2楼 NaturalJ0 | 发表于 2006-08-15 23:07 |
| 银牌会员 发帖 533 积分 1,181 | |
|
用 IF EXIST 判断是否有目录
多用几个变量 判断变量用不同的 CHOICE [ Last edited by NaturalJ0 on 2006-8-16 at 09:17 ] |
|
| 第3楼 fastslz | 发表于 2006-08-15 23:23 |
| 铂金会员 发帖 2,315 积分 5,493 来自 上海 | |
|
@echo off
if exist c:\d\* set menu=12345 if "%menu%"=="12345" goto ok if exist c:\c\* set menu=1234 if "%menu%"=="1234" goto ok if exist c:\b\* set menu=123 if "%menu%"=="123" goto ok if exist c:\a\* set menu=12 if "%menu%"=="12" goto ok if "%menu%"=="" goto error :ok echo 按键1........ for %%a in (12 123 1234 12345) do if "%menu%"=="%%a" echo 按键2........ for %%a in (123 1234 12345) do if "%menu%"=="%%a" echo 按键3........ for %%a in (1234 12345) do if "%menu%"=="%%a" echo 按键4........ if "%menu%"=="12345" echo 按键5........ choice/c:%menu% IF errorlevel 1 if not errorlevel 2 goto 1 IF errorlevel 2 if not errorlevel 3 goto 2 IF errorlevel 3 if not errorlevel 4 goto 3 IF errorlevel 4 if not errorlevel 5 goto 4 IF errorlevel 5 if not errorlevel 6 goto 5 :error [ Last edited by fastslz on 2006-8-16 at 01:48 ] |
|
| 第4楼 BAT | 发表于 2006-08-16 22:48 |
| 初级用户 发帖 52 积分 177 | |
|
谢谢fastslz兄提供的解决问题的思路,不过方法判断方法似乎存在问题,
如果存在c:\d\*.* set menu=12345,goto ok 下面的四个FOR语句将产生五个echo 而事实上仅存在一个文件夹, 还是我没有理解lastslz兄的内容? [ Last edited by BAT on 2006-8-16 at 22:54 ] |
|
| 第5楼 fastslz | 发表于 2006-08-16 23:11 |
| 铂金会员 发帖 2,315 积分 5,493 来自 上海 | |
|
确实没理解,看下面2个例子
假设C盘有B文件夹此时会出现如下 @echo off echo 按键1........ echo 按键2........ echo 按键3........ choice/c:123 IF errorlevel 1 if not errorlevel 2 goto 1 IF errorlevel 2 if not errorlevel 3 goto 2 IF errorlevel 3 if not errorlevel 4 goto 3 IF errorlevel 4 if not errorlevel 5 goto 4 IF errorlevel 5 if not errorlevel 6 goto 5 假设C盘有D文件夹此时会出现如下 @echo off echo 按键1........ echo 按键2........ echo 按键3........ echo 按键4........ echo 按键5........ choice/c:12345 IF errorlevel 1 if not errorlevel 2 goto 1 IF errorlevel 2 if not errorlevel 3 goto 2 IF errorlevel 3 if not errorlevel 4 goto 3 IF errorlevel 4 if not errorlevel 5 goto 4 IF errorlevel 5 if not errorlevel 6 goto 5 也就是说choice有5个选择就出现5个echo 提示信息,有3个选择只出现3个echo 提示信息 |
|
| 第6楼 BAT | 发表于 2006-08-17 20:26 |
| 初级用户 发帖 52 积分 177 | |
|
fastslz兄,我刚才又验证了一下你的代码,
如果,只存在a,没错,是choice/c12 如果,存在a,b,没错,是choice/c123 如果,存在a,b,c,没错,是choice/c1234 如果,存在a,b,c,d没错,是choice/c12345 但倘若我删除a,b文件夹,但仍然是choice/c12345 但此时需要的是choice/c123 我只保留c文件夹,此时出现的是choice/c1234 而此时因为只存在一个符合要求的文件夹,所以需要的是choice/c12 而不是choice/c1234 |
|
| 第7楼 fastslz | 发表于 2006-08-17 21:45 |
| 铂金会员 发帖 2,315 积分 5,493 来自 上海 | |
|
CHOICE动态选择已经没问题了,要符合什么要求你也没说明。自己摸索一下吧。
就6楼的要求我也没理解能说明白一点吗 如果存在a,b,c,d你想怎么做? 如果存在a,b,c你想怎么做? 如果存在a,b你想怎么做? 如果存在a你想怎么做? 也就改变一下的变量而已,自己摸索一下吧。 [ Last edited by fastslz on 2006-8-17 at 21:47 ] |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |