连接变量

Uca*_*oIt 42 batch-file

我需要为DOS做一个.bat执行以下操作:

set ROOT = c:\programas\
set SRC_ROOT = (I want to put the ROOT Here)System\Source
Run Code Online (Sandbox Code Playgroud)

所以在定义ROOT后我想要SRC_ROOT = c:\ programas\System\Source

我怎样才能做到这一点?

pod*_*sta 57

设置ROOT = c:\ programs设置SRC_ROOT =%ROOT%\ System\Source

顺便说一下,|的含义是什么 ROOT之后?误导?

格雷瓜尔

编辑:没有空格

set ROOT=c:\programs 
set SRC_ROOT=%ROOT%\System\Source
Run Code Online (Sandbox Code Playgroud)


Her*_*ess 11

请注意,如果需要空格,则在定义时需要引号,并且在连接时必须将其切断:

rem The retail files set
set FILES_SET="(*.exe *.dll"

rem The debug extras files set
set DEBUG_EXTRA=" *.pdb"

rem Build the DEBUG set without any
set FILES_SET=%FILES_SET:~1,-1%%DEBUG_EXTRA:~1,-1%

rem Append the closing bracket
set FILES_SET=%FILES_SET%)

echo %FILES_SET%
Run Code Online (Sandbox Code Playgroud)

干杯...


vll*_*vll 6

如果需要用引号连接路径,可以使用=替换变量中的引号。这不需要您知道路径是否已经包含引号。如果没有引号,则没有任何更改。

@echo off
rem Paths to combine
set DIRECTORY="C:\Directory with spaces"
set FILENAME="sub directory\filename.txt"

rem Combine two paths
set COMBINED="%DIRECTORY:"=%\%FILENAME:"=%"
echo %COMBINED%

rem This is just to illustrate how the = operator works
set DIR_WITHOUT_SPACES=%DIRECTORY:"=%
echo %DIR_WITHOUT_SPACES%
Run Code Online (Sandbox Code Playgroud)