Batch file: & filename with ampersand
Posted: Wed Oct 21, 2015 3:59 am
(Windows 7)
Batch file: & filename containing an ampersand (&)
I want to drag & drop (or SendTo) a set of files to a batch file.
All works fine - unless the filename (including path) includes an ampersand (&) (& I imagine a few other chars; ^ ( ), maybe more).
MUX.BAT:
I have a file named "A&V" (& "V&A") that I want to drop onto MUX.BAT.
No matter what I've tried, I can't seem to get DRAGNDROP correct?
Results:
> DRAGNDROP == "C:\BIN\a"
I'm looking to get, expecting:
> DRAGNDROP == "C:\BIN\a&v"
I can supply "a&v" as a command-line argument to MUX.BAT, & that will set DRAGNDROP as wanted.
But I can't seem to get a drag & drop to do the same.
I can set a variable from within the batch file itself & that works [V=].
I can then reference that variable from within the batch file & that works [W=]
I can then ECHO V & W, & that works.
%cmdcmdline% shows the entire command line & that looks OK too.
Ideas?
Batch file: & filename containing an ampersand (&)
I want to drag & drop (or SendTo) a set of files to a batch file.
All works fine - unless the filename (including path) includes an ampersand (&) (& I imagine a few other chars; ^ ( ), maybe more).
MUX.BAT:
Code: Select all
@ECHO OFF
setlocal enableDelayedExpansion
set "V=a&v"
set "W=%V%"
set "DRAGNDROP=%~1"
set V
set W
echo "%DRAGNDROP%"
echo %cmdcmdline%
pause
exit
No matter what I've tried, I can't seem to get DRAGNDROP correct?
Results:
Code: Select all
V=a&v
W=a&v
windir=E:\Windows
V == "a&v"
W == "a&v"
DRAGNDROP == "C:\BIN\a"
COMMANDLINE == E:\Windows\system32\cmd.exe /c ""C:\BIN\MUX.BAT" C:\BIN\a&v C:\BIN\v&a"
I'm looking to get, expecting:
> DRAGNDROP == "C:\BIN\a&v"
I can supply "a&v" as a command-line argument to MUX.BAT, & that will set DRAGNDROP as wanted.
But I can't seem to get a drag & drop to do the same.
I can set a variable from within the batch file itself & that works [V=].
I can then reference that variable from within the batch file & that works [W=]
I can then ECHO V & W, & that works.
%cmdcmdline% shows the entire command line & that looks OK too.
Ideas?