Ampersand is directory name - Batch not working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Andreas
Posts: 1
Joined: 05 Dec 2018 12:08

Ampersand is directory name - Batch not working

#1 Post by Andreas » 05 Dec 2018 12:20

Hallo!

Ich bin momentan auf der Suche nach einer Lösung für folgendes Problem:

Biespiel 1 (WORKING)
C:\Test and Test\script.bat
in diesem file steht folgendes: start "Firefox" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.google.com
Klickt auf die .bat-datei öffnet sich der browser und die website wird geladen!

Beispiel 2 (NOT WORKING)
C:\Test & Test\script.bat
in diesem file steht folgendes: start "Firefox" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.google.com
Klickt auf die .bat-datei öffnet sich kein browser und entsprechend wir die website auch nicht geladen.

Folgendes habe ich bereits - leider ohne Erfolg - versucht:

set "filelocation=C:\Test & Test" bzw. set "filelocation=C:\Test ^& Test"
cd "%filelocation%"
start "Firefox" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.google.com

Vielleicht kann mir jemand weiterhelfen. Grundlegend funktioniert alles, wenn es kein "&" im Pfad gibt.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Ampersand is directory name - Batch not working

#2 Post by Ed Dyreen » 06 Dec 2018 00:53

Andreas wrote:
05 Dec 2018 12:20
Hallo!

Ich bin momentan auf der Suche nach einer Lösung für folgendes Problem:

Biespiel 1 (WORKING)
C:\Test and Test\script.bat
in diesem file steht folgendes: start "Firefox" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.google.com
Klickt auf die .bat-datei öffnet sich der browser und die website wird geladen!

Beispiel 2 (NOT WORKING)
C:\Test & Test\script.bat
in diesem file steht folgendes: start "Firefox" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.google.com
Klickt auf die .bat-datei öffnet sich kein browser und entsprechend wir die website auch nicht geladen.

Folgendes habe ich bereits - leider ohne Erfolg - versucht:

set "filelocation=C:\Test & Test" bzw. set "filelocation=C:\Test ^& Test"
cd "%filelocation%"
start "Firefox" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.google.com

Vielleicht kann mir jemand weiterhelfen. Grundlegend funktioniert alles, wenn es kein "&" im Pfad gibt.
Your last example is correct, the ampersand has special meaning in dos, this is why it is interpreted literally only when escaped with a caret or in double-quotes. I do not understand what you are trying to do with Firefox because as you, I am too lazy to use google translate.

Your topic was approved but you will continue in English or the topic will be locked, this is not a German site.

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Ampersand is directory name - Batch not working

#3 Post by jeb » 06 Dec 2018 05:57

Hi Andreas,

I suppose there is more in your batch file, because I just tested this sample batch file in a directory named "C:\temp\amp & ersand\" and it works

Code: Select all

@echo off
setlocal EnableDelayedExpansion
echo cmdcmdline: !cmdcmdline!
start "Firefox" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" http://www.google.com
pause > nul
jeb

Post Reply