这就是我需要的。
假设有一个文件temp.txt 让我们说temp.txt有以下内容:
name=@name
age=@age
email=@email
我的批处理文件create.bat应该要求三个参数作为用户的输入, 然后用相应的值替换temp.txt。
称。
Pls enter your name:Tom
Tom - Confirm Y/N: Y
<<now anywhere the temp.txt says @name, it is replace by Tom>>
请帮我写一个脚本吗?
谢谢, 纳温。
答案 0 :(得分:0)
rem @echo off
setlocal enabledelayedexpansion enableextensions
rem Don't use the same file name for both here
set InputFile=temp.txt
set OutputFile=temp2.txt
call :ask name name
call :ask age age
call :ask "e-Mail address" email
del %OutputFile% 1>nul 2>&1
for /f "delims=" %%l in (%InputFile%) do (
set Line=%%l
set Line=!Line:@name=%name%!
set Line=!Line:@age=%age%!
set Line=!Line:@email=%email%!
>>%OutputFile% echo.!Line!
)
goto :eof
rem :ask "placeholder title" variable_name
:ask
set /p %2=Please enter your %~1:
choice /M "!%2! - Confirm"
if errorlevel 2 goto ask
goto :eof