![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-06 20:44 |
共 48,039 主题排行 / 350,124 发帖 / 今日 0 篇 / 48,252 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » [求助]请帮助我分析这段代码? |
| 可打印版本 664 / 5 |
| 第1楼 tempuser | 发表于 2007-12-13 09:17 |
| 高级用户 发帖 261 积分 547 | |
|
[求助]请帮助我分析这段代码? 在网上看到,这是限制使用次数的代码
@echo off echo echo 000>>test1.txt attrib test1.txt +s +h type test1.txt | find /c /n "000">>test2.txt attrib test2.txt +s +h FOR /f "delims=" %%i in ('find test2.txt "5"') do (set no=%%i) if "%no%" == "5" del %0&&exit pause 我的问题是以下行该怎么理解: FOR /f "delims=" %%i in ('find test2.txt "5"') do (set no=%%i) 是从test2.txt中查找字符串5吗?那么把什么值赋给i呢? 我在该命令行下面加个 echo %no%,为什么总是显示--------test2.txt呢?下面是我的修改代码,到是能限制使用次数,但对于变量的赋值是如何变化的,还是很糊度! @echo off echo 限制使用次数为5 :loop set /a var+=1 echo %var% pause echo echo 000>>test1.txt attrib test1.txt +s +h type test1.txt | find /c /n "000">>test2.txt attrib test2.txt +s +h FOR /f "delims=" %%i in ('find test2.txt "5"') do (set no=%%i) echo %no% ::最初认为是在test2.txt中查数字5,其实这么理解是错误的! if "%no%" == "5" del %0 goto loop pause |
|
| 第2楼 tempuser | 发表于 2007-12-13 09:19 |
| 高级用户 发帖 261 积分 547 | |
|
echo %no%为什么不是
1 2 3 4 5 这样的呢? |
|
| 第3楼 huahua0919 | 发表于 2007-12-13 11:06 |
| 银牌会员 发帖 780 积分 1,608 | |
|
'find test2.txt "5"'
find 命令中,我没见过这种用法,还望高手指点! |
|
| 第4楼 terse | 发表于 2007-12-13 11:25 |
| 银牌会员 发帖 946 积分 2,404 | |
|
find "5" "test2.txt" find test2.txt "5" 哈哈 似乎一样用啊
[ Last edited by terse on 2007-12-13 at 11:31 AM ] |
|
| 第5楼 huahua0919 | 发表于 2007-12-13 11:31 |
| 银牌会员 发帖 780 积分 1,608 | |
|
楼上的我知道,但是在find文档里面并没有这样的说法,但是楼主的也可以执行,费解~
|
|
| 第6楼 terse | 发表于 2007-12-13 11:41 |
| 银牌会员 发帖 946 积分 2,404 | |
|
find "5" "test2.txt" 文件名可以用“”
find test2.txt "5" 中文件名不可以用“” 文件名有空格就不能处理 |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |