Passing path with '&' to batch file

I am trying to transfer the path to a batch file from another program. Another program uses BASIC as a scripting language.

So, I invoke the batch file using the Shell () command.

In a shell command, I'm trying to pass a path with the '&' character. However, by the time it gets into the batch file, the batch file is also considered as some escape sequence (I think).

For instance:

Path: C: \ Documents \ R & D \ Files

Shell("runscript.bat "C:\Documents\R&D\Files"")

In the batch file:

variable=~1
echo %variable%

I get the following output:

C: Documents \ R

UPDATE

However, if I use a path like C: \ Documents \ RD \ Files

This path will go through find, and the echo will print:

C: \ Documents \ RD \ Files

+4
2

, ( ). ( ! %):

set "variable=%~1"
echo "%variable%"
setlocal enableDelayedExpansion
echo !variable!

, &

for /f:

for /f %%a in ("%~1") do echo %%a
+3

Windows ^ . R^&D, :

C:\Users\Thomas>echo R^&D
R&D
0

All Articles