这批命令的含义是什么?

Zeu*_*eus 4 batch-file

setlocal enabledelayedexpansion
for /f "delims=" %%a in (%TempFile2%) do (
    set a=%%a
    set a=!a: =!   
    echo !a! >>%DataFile%
)
Run Code Online (Sandbox Code Playgroud)

我知道代码会查找tempfile2数据中的每个"空白空间"并设置它.这条线是什么意思?

设a =!a:=!

谢谢

Mic*_*urr 6

这是一个基本的模式匹配和替换.

这是以下方面的帮助set /?:

Environment variable substitution has been enhanced as follows:

    %PATH:str1=str2%

would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2".  "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output.  "str1" can begin with an asterisk, in which case it will match
everything from the beginning of the expanded output to the first
occurrence of the remaining portion of str1.
Run Code Online (Sandbox Code Playgroud)

您的示例中的其他扭曲是使用了'延迟扩展'语法,它使用!字符作为环境变量扩展字符而不是%.

因此该命令set a=!a: =!将从变量的内容中删除所有空格字符a.

延迟扩展是需要的(或至少使像这样容易一点),因为该方法的cmd.exe的正常膨胀(然后使用%分隔符)在执行它的任何部分之前,由括号包围的块整个集合的命令的.