|
在特定条件下,批处理能将自身某一块或某N块的内容输出为某一文件,这些条件有(满足其中一条即可):
1、信息块本身有CMD能处理的起止标记;
2、信息块位于文件中某些特定的行;
以下是一些演示代码:
- @echo off
- :: 把以 :start 开始,goto :eof之前的信息段输出到test.txt
- cd.>test.txt
- set switch=1
- for /f "delims=" %%i in ('findstr .* "%~0"') do (
- if /i "%%i"==":start" set switch=
- if /i "%%i"=="goto :eof" set switch=1
- if not defined switch >>test.txt echo.%%i
- )
- start test.txt
- exit
- :start
- @echo off
- echo hello world
- pause>nul
- goto :eof
- :end
- exit
复制代码
- @echo off
- :: 把 :start 标签段的信息段输出到test.txt(忽略空行)
- cd.>test.txt
- set num=0
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('findstr .* "%~0"') do (
- set /a num+=1
- if !num! gtr 12 if !num! lss 17 >>test.txt echo.%%i
- )
- start test.txt
- exit
- :start
- @echo off
- echo hello world
- pause>nul
- goto :eof
- :end
- exit
复制代码
- @echo off
- :: 将 :start 之后的所有内容输出到 test.txt
- >test.txt more +7 "%~0"
- start test.txt
- goto :eof
- :start
- @echo off
- echo hello world
- pause>nul
- :next
- @echo off
- echo hell bbs.wuyou.net
- pause>nul
复制代码
[ 本帖最后由 namejm 于 2006-12-7 10:56 PM 编辑 ] |
|