<http://www.netikka.net/tsneti/info/tscmd058.htm>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Mon 10-May-2010 14:57:56

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



58} How do I best combine two quoted arguments into one quoted string?

Consider two cases. First, the arguments are in environment variables:
  @echo off & setlocal enableextensions
  set x_="C:\Program Files\Schedule\"
  set y_="My log.txt"
  set z1_="%x_:"=%%y_:"=%"
  echo.%z1_%
  goto :EOF

The output will be
  D:\TEST>cmdfaq
  "C:\Program Files\Schedule\My log.txt"

Second, the argument are given as replaceable parameters to the script:
  @echo off & setlocal enableextensions
  set z2_="%~1%~2"
  echo.%z2_%
  goto :EOF

The output will be
  D:\TEST>cmdfaq "C:\Program Files\Schedule\" "My log.txt"
  "C:\Program Files\Schedule\My log.txt"
The tilde ~ is essential in the second version. As the documentation about "Using batch parameters" in "Command-line reference" says: %~1 Expands %1 and removes any surrounding quotation marks ("").

Alternatively, (since e.g. NT4 does not recognize the ~trick) one could use
  @echo off & setlocal enableextensions
  set x_=%1
  set y_=%2
  set z1_="%x_:"=%%y_:"=%"
  echo.%z1_%
  goto :EOF