在网上看到,这是限制使用次数的代码
@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
@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
