How do you add a variable to a string in a batch file?

时间:2019-05-19 04:14:32

标签: batch-file environment-variables variable-assignment

I can't seem to find how to do this simple task, and this is probably answered.

How does one add a string to a variable? such as set "FileNameAndPCName = Locker\ and add %COMPUTERNAME%" to the variable so it would become like, "Locker/Bill"?

Code:

@echo off
set FileNameAndPCName="Locker\" + "%COMPUTERNAME%"
echo %FileNameAndPCName%
pause

1 个答案:

答案 0 :(得分:0)

批量操作已经是字符串操作,因此您不需要也不能使用def extract_overview(content): ... def extract_takeaways(content): ... EXTRACTORS = { 'overview': extract_overview, 'takeaways': extract_takeaways, ... } for tag in tags: heading = tag.get_attribute("textContent").lower().strip() content = tag.parent for substring, function in EXTRACTORS.items(): if substring in heading: result = function(content) break else: # No extractor was found 连接字符串。像这样输入整个字符串

+

set "FileNameAndPCName=Locker\%COMPUTERNAME%" 将按字面意义将变量set FileNameAndPCName="Locker\" + "%COMPUTERNAME%"设置为%FileNameAndPCName%(替换为"Locker\" + "%COMPUTERNAME%"之后。%COMPUTERNAME%命令中的引号不是特殊的。并且还建议这样做使用set而不是set "var=value"的变体,以避免结尾处出现意外的尾随空格