@echo off
:start
cls
Title Like or unlike
:1
echo.
set/p _file=output file name:
echo.
echo select the type
echo (1)like. (2)unlike
echo.
set/p _num=enter your option:
if %_num%==1 goto Like
if %_num%==2 goto Unlike
:Like
echo.
COPY the below lines to "%_file%"
The land is beautiful
I wanna stay here
etc........
etc........
exit
:unlike
echo.
COPY the below lines to "%_file%"
The land is ugly
I hate this land
exit
我想创建.bat文件,将.bat文件中的选定行(在.bat文件中)复制到另一个文本文件
答案 0 :(得分:1)
@echo OFF
setlocal
:start
CLS
Title Like or unlike
:1
echo.
set/p _file=output file name:
echo.
echo select the type
echo (1)like. (2)unlike
echo.
set/p _num=enter your option:
if %_num%==1 CALL :show Like&GOTO :eof
if %_num%==2 CALL :show UnLike&GOTO :eof
ECHO BAD OPTION
GOTO :EOF
:show
SET "out="
FOR /f "usebackq tokens=1*" %%i IN ("%~dpnx0") DO (
IF /i %%i==exit SET "OUT="
IF DEFINED out >>"%_file%" echo %%i %%j
IF /i %%i==:%1 SET OUT=Y
)
GOTO :eof
:Like
The land is beautiful
I wanna stay here
etc........
etc........
exit
:unlike
The land is ugly
I hate this land
exit
这是一个首发。它并不完美。请注意%~dpnx0
(或%~f0
)是第0批参数的驱动器路径名扩展名,即批处理文件本身
答案 1 :(得分:1)
试试这个:
(Echo The land is beautiful
echo I wanna stay here
echo etc........
echo etc........
)>"%_file%"
答案 2 :(得分:0)
使用以下行
Echo The land is beautiful >> %_file%
echo I wanna stay here >> %_file%
echo etc........ >> %_file%
echo etc........ >> %_file%