concatenate variables

后端 未结 3 1948
闹比i
闹比i 2021-02-03 17:20

I need to do a .bat for DOS that do the following:

set ROOT = c:\\programas\\
set SRC_ROOT = (I want to put the ROOT Here)System\\Source

so aft

相关标签:
3条回答
  • 2021-02-03 17:49

    If you need to concatenate paths with quotes, you can use = to replace quotes in a variable. This does not require you to know if the path already contains quotes or not. If there are no quotes, nothing is changed.

    @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%
    
    0 讨论(0)
  • 2021-02-03 17:49

    Note that if strings has spaces then quotation marks are needed at definition and must be chopped while concatenating:

    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%
    

    Cheers...

    0 讨论(0)
  • 2021-02-03 17:55
    set ROOT=c:\programs 
    set SRC_ROOT=%ROOT%\System\Source
    
    0 讨论(0)
提交回复
热议问题