Search code examples
batch-filespecial-charactersconcatenationdos

Batch File Concatenation With Special Character


I need to create a string variable in my DOS Batch file to contain the following: "Server1\StoreDB"

My StoreDB is coming from a query to the database so currently, my script looks like this:

set Instance=%1
set path1="Server1\"
set "CompletePath=%path1%%Instance%"

But this doesn't return "Server1\StoreDB". It only returns "StoreDB"

A little help here please? I am new to these DOS commands. Thank you.


Solution

  • You have problems/potential problems with quotes. Use %~1 instead of %1 to remove potential quotes. The placement of quotes in your second line is incorrect.

    set Instance=%~1
    set "path1=Server1\"