【发布时间】:2013-04-24 23:51:13
【问题描述】:
我在下面描述的功能是否可以使用批处理 Windows 脚本?如果是这样,我该如何编辑我的代码来执行此功能?
我正在尝试从文件中删除多行字符串。多行字符串来自另一个文件并被读入批处理变量。然后我读取目标文件并搜索这个多行字符串,如果它存在我想从目标文件中删除它。
我下面的代码无法从目标文件中删除多行字符串。它可以成功读取输入文件。 您能帮我编辑脚本以从文件中搜索和删除多行字符串吗?
@echo off &setlocal enabledelayedexpansion
Set replace=
Set target=
Set infile=usermenuTest1.4d
Set outfile=usermenuTest2.4d
Rem Read file and store all contents in string
for /f "delims=" %%i in (%infile%) do set "target=!target! %%i"
echo %target%
Rem Remove the target string from outfile
@echo off & setlocal enabledelayedexpansion
for /f "tokens=1,* delims=¶" %%A in ( 'type "%outfile%"') do SET "string=%%A"
SET "modified=!string:%target%=%replace%!"
(echo(%modified%)>> "%outfile%"
ECHO.
PAUSE
ENDLOCAL
基本上我希望我的脚本从文件中删除以下 bold(the text inside **) 文本:
// abc // def // hij **Menu "User" { Button "" { Walk_Right "" } }**
【问题讨论】:
-
你需要使用批处理吗?你不能使用powershell或vbs吗?
-
@Carko Powershell 或 VBS 脚本能否在 Windows XP 及更高版本上运行?我正在分发一个将调用此脚本的安装程序,因此用户需要能够编译和运行该脚本。 Python 会是最简单的,但不是每个人都会安装 Python 解释器
标签: windows batch-file