Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 串联变量_Batch File - Fatal编程技术网

Batch file 串联变量

Batch file 串联变量,batch-file,Batch File,我需要为DOS执行.bat操作,它可以执行以下操作: set ROOT = c:\programas\ set SRC_ROOT = (I want to put the ROOT Here)System\Source 因此,在定义ROOT之后,我希望SRC\u ROOT=c:\programas\System\Source 怎么做?请注意,如果字符串有空格,则在定义时需要引号,并且必须在连接时截断: set ROOT=c:\programs set SRC_ROOT=%ROOT%\Syst

我需要为DOS执行.bat操作,它可以执行以下操作:

set ROOT = c:\programas\
set SRC_ROOT = (I want to put the ROOT Here)System\Source
因此,在定义ROOT之后,我希望SRC\u ROOT=c:\programas\System\Source


怎么做?

请注意,如果字符串有空格,则在定义时需要引号,并且必须在连接时截断:

set ROOT=c:\programs 
set SRC_ROOT=%ROOT%\System\Source
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%

干杯…

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

@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%

对这是一个错误的销售。。。你写的是我尝试过的第一件事。。。它不起作用。。。如果我对SRC_ROOT only\system | source进行了回显实际上,=之间的空格不是必需的,请尝试:set ROOT=c:\programs set SRC_ROOT=%ROOT%\system\source您是否可以发布整个脚本以了解问题,在我的命令提示符下,这两个命令正在运行,ECHO%SRC_ROOT%给了我正确的答案。它正在运行。非常感谢:)顺便说一句,想象一下我现在想打开一个txt文件,并将:set ROOT=我从文件中捕获的字符串放入其中?我该怎么做呢?对不起,我不明白你打开一个txt文件并放入“set ROOT=string”是什么意思。