看不懂。又如何使用?
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo off
setlocal enabledelayedexpansion
set count=0
set /p newname=请输入:
type nul>"test.bak"
for /f "tokens=1,2* delims=:" %%a in ('findstr /n .* "test.rc"') do (
>>"test.bak" echo.%%b
set /a count+=1
if !count! equ 4 goto :next
)
goto :eof
:next
>>"test.bak" echo 578, "%newname%"
for /f "skip=5 tokens=1,2* delims=:" %%a in ('findstr /n .* "test.rc"') do (
>>"test.bak" echo.%%b
)
move /y "test.bak" "test.rc"
@echo off
setlocal enabledelayedexpansion
set count=0
set newname=
:begin
set /p newname=请输入:
if "%newname%" equ "" (
echo 输入不能为空
goto :begin
)
type nul>"test.bak"
for /f "tokens=1,2* delims=:" %%a in ('findstr /n .* "test.rc"') do (
>>"test.bak" echo.%%b
set /a count+=1
if !count! equ 4 goto :next
)
goto :eof
:next
>>"test.bak" echo 578, "%newname%"
for /f "skip=5 tokens=1,2* delims=:" %%a in ('findstr /n .* "test.rc"') do (
>>"test.bak" echo.%%b
)
move /y "test.bak" "test.rc"
Originally posted by HAT at 2008-9-9 03:43 AM:
经测试,17楼的代码不管第几次回车,总是能够正确替换test.rc的内容。
至于你说的“之后就不能替换成空字符了”,能描述一下你是怎样测试的不?
@echo off
setlocal enabledelayedexpansion
set count=0
set newname=
set /p newname=请输入:
type nul>"test.bak"
for /f "tokens=1,2* delims=:" %%a in ('findstr /n .* "test.rc"') do (
>>"test.bak" echo.%%b
set /a count+=1
if !count! equ 4 goto :next
)
goto :eof
:next
>>"test.bak" echo 578, "%newname%"
for /f "skip=5 tokens=1,2* delims=:" %%a in ('findstr /n .* "test.rc"') do (
>>"test.bak" echo.%%b
)
move /y "test.bak" "test.rc"
| 评分人 | 分数 | 时间 |
|---|---|---|
| tireless | +8 | 2008-09-10 01:26 |