【发布时间】:2022-01-10 21:46:08
【问题描述】:
我无法让它工作。我正在逐行读取 XML 文件,然后查看每一行是否包含特定标记
@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
....some more code....
SET dllFile=%DestPath%\%ProjectName%.dll.manifest
IF NOT EXIST "%dllFile%" (
ECHO File %ProjectName%.dll.manifest does not exist^^!
GOTO ERROR
) ELSE (
ECHO Modifying %ProjectName%.dll.manifest in directory:
ECHO %DestPath%
REM Create a temporary file in the folder, where this batch file is being executed from
>"temp.xml" (
FOR /F "usebackq delims=" %%I IN ("%dllFile%") DO (
SET "line=%%I"
REM Insert existing line before modification
SETLOCAL DisableDelayedExpansion
ECHO %%I
ENDLOCAL
REM Find correct version number
SET "myVariable=<assemblyIdentity name="PostDeploymentAction" version"
IF not "!line!"=="!line:myVariable=!" (
echo !line!
)
....some more code....
)
)
)
无论我使用什么转义字符,它都不会找到这个特定的行(或者它会找到每一行)。上面代码中的其他所有内容都可以正常工作 - 只有 IF not "!line!"=="!line:myVariable=!" 不能。非常感谢任何帮助。
谢谢
【问题讨论】:
-
为什么要分配临时变量
myVariable? -
那是我拼命尝试解决 IF 语句中的双引号问题...
-
我刚刚在搜索字符串中发现了一个
=-符号,这是不可能的,因为这样可以分隔搜索字符串和替换字符串……
标签: batch-file substring quotes