此批处理脚本的要点是获取用户输入的帐号,并将包含该帐号的文本文件中的行替换为“xxxxxxxxxxxxxxxxxxxxx”。我该怎么做呢?现在它只显示帐号的帐户信息。
set /p acct_code=Enter account code:
echo.
setlocal ENABLEDELAYEDEXPANSION
set flag=0
for /f "tokens=1-3 delims=," %%r in (accounts.txt) do (
if %%r==!acct_code! (
cls
echo Account Information
echo *******************
echo Account Code : %%r
echo Account Name : %%s
echo Account Balance : %%t
set flag=1
)
)
if !flag!==0 echo Account NOT Found, Please Try Again...
echo.
PAUSE
cls
答案 0 :(得分:0)
你错过了再次写入行的代码(到新文件):
...
for /f "tokens=1-3 delims=," %%r in (accounts.txt) do (
if %%r==!acct_code! (
cls
echo Account Information
echo *******************
echo Account Code : %%r
echo Account Name : %%s
echo Account Balance : %%t
echo(%r,%%s,%%t >>accounts.new
set flag=1
) else (
echo xxxxxxxxxxxxxxxxxxxxx>>accounts.new
)
)
ECHO move /y accounts.new accounts.txt
...
(注意:要实际重命名新文件(覆盖原始文件),请删除ECHO
之前的move