返回列表 发帖
:0
@echo off
for /f "delims=" %%a in ('type %0') do (set "str=%%a"&goto :out)
:out
set "str=%str::=%"
set /a "str+=1"
for /f "delims=" %%a in ('type %0') do (
   if not defined god (
      set god=hell
      >%0 echo :%str%
   ) else (
       >>%0 echo %%a
   )
)
if %str% gtr 1 (echo %str% times already) else (echo This is the first time)
rem 如果上面这行有中文会出错,不解...
set "god="&pause>nul&goto :%str%COPY


[ 本帖最后由 more 于 2008-10-24 00:52 编辑 ]

TOP

原帖由 pusofalse 于 2008-10-24 13:58 发表
回复more兄,好像看错题意了。第一次运行时什么也不会输出,到运行第二次时才输出“已经运行1次”。25楼同是如此的问题。

我这里显示没有问题呀:
This is the first time
2 times already
3 times already
4 times already
5 times already
6 times already

TOP

回39楼 shqf

这样算吗?
@echo off
set "str=echo 这里是中间那段"
for /f "delims=" %%a in ('type %0') do (
   if not defined god (
      set "god=hell"
      >%0 echo %%a
   ) else (
      if not "%%a"=="%str%" (
         >>%0 echo %%a
      ) else (
         >>%0 echo echo 这里是已经改写的中间那段
      )
   )
)
echo 这里是中间那段
pauseCOPY

TOP

返回列表