标题: [求助]请帮助我分析这段代码?
[打印本页]
作者: tempuser
时间: 2007-12-13 09:17
标题: [求助]请帮助我分析这段代码?
在网上看到,这是限制使用次数的代码
@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
作者: tempuser
时间: 2007-12-13 09:19
echo %no%为什么不是
1
2
3
4
5
这样的呢?
作者: huahua0919
时间: 2007-12-13 11:06
'find test2.txt "5"'
find 命令中,我没见过这种用法,还望高手指点!
作者: terse
时间: 2007-12-13 11:25
find "5" "test2.txt" find test2.txt "5" 哈哈 似乎一样用啊
[
Last edited by terse on 2007-12-13 at 11:31 AM ]
作者: huahua0919
时间: 2007-12-13 11:31
楼上的我知道,但是在find文档里面并没有这样的说法,但是楼主的也可以执行,费解~
作者: terse
时间: 2007-12-13 11:41
find "5" "test2.txt" 文件名可以用“”
find test2.txt "5" 中文件名不可以用“” 文件名有空格就不能处理