0
@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 文件中)复制到另一个文本文件

4

3 回答 3

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个批处理参数的驱动器路径名扩展名,也就是批处理文件本身

于 2013-07-15T16:30:51.510 回答
1

尝试这个:

(Echo The land is beautiful
echo I wanna stay here
echo etc........ 
echo etc........  
)>"%_file%"
于 2013-07-15T16:32:00.020 回答
0

使用以下行

Echo The land is beautiful >> %_file%
echo I wanna stay here  >> %_file%
echo etc........  >> %_file%
echo etc........  >> %_file%
于 2013-07-15T15:57:45.013 回答