Skip to content

Instantly share code, notes, and snippets.

@hallvors
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallvors/eb4a622686bf87cbb4bb to your computer and use it in GitHub Desktop.
Save hallvors/eb4a622686bf87cbb4bb to your computer and use it in GitHub Desktop.
Testing how Windows handles quoted paths in a batch file
@echo off
setlocal EnableDelayedExpansion
set SLJS_TEST=%SLJS_TEST%
echo.
echo No quotes added. Path is %SLJS_TEST%
echo.
if exist %SLJS_TEST% (
echo "UNQUOTED: This path DOES exist: %SLJS_TEST%"
)
if not exist %SLJS_TEST% (
echo "UNQUOTED: This path does NOT exist: %SLJS_TEST%"
)
echo.
if exist "%SLJS_TEST%" (
echo "QUOTED IN EXISTS STATEMENT: This path DOES exist: %SLJS_TEST%"
)
if not exist "%SLJS_TEST%" (
echo "QUOTED IN EXISTS STATEMENT: This path does NOT exist: %SLJS_TEST%"
)
echo.
echo.
set SLJS_TEST="%SLJS_TEST%"
rem set SLJS_TEST="c:\Program Files (x86)\Mozilla Firefox\firefox.exe"
echo.
if exist %SLJS_TEST% (
echo QUOTE PART OF VALUE, UNQUOTED STATEMENT: This path DOES exist: %SLJS_TEST%
)
if not exist %SLJS_TEST% (
echo QUOTE PART OF VALUE, UNQUOTED STATEMENT: This path does NOT exist: %SLJS_TEST%
)
echo.
echo.
if exist "%SLJS_TEST%" (
echo QUOTE PART OF VALUE, QUOTED STATEMENT: This path DOES exist: %SLJS_TEST%
)
if not exist "%SLJS_TEST%" (
echo QUOTE PART OF VALUE, QUOTED STATEMENT: This path does NOT exist: %SLJS_TEST%
)
echo.
echo.
rem if exist "%programfiles%\Mozilla Firefox\firefox.exe" (
rem SET "SLIMERJSLAUNCHER=%programfiles%\Mozilla Firefox\firefox.exe"
rem )
rem if exist "%programfiles(x86)%\Mozilla Firefox\firefox.exe" (
rem SET "SLIMERJSLAUNCHER=%programfiles(x86)%\Mozilla Firefox\firefox.exe"
rem )
rem echo "Found Firefox here: %SLIMERJSLAUNCHER%"
@hallvors
Copy link
Author

Win XP, 32 bit, spaces in path, no quotes in environment variable:

No quotes added. Path is c:\Program Files\Mozilla Firefox\firefox.exe

"UNQUOTED: This path DOES exist: c:\Program Files\Mozilla Firefox\firefox.exe"
The system cannot find the path specified.
"UNQUOTED: This path does NOT exist: c:\Program Files\Mozilla Firefox\firefox.exe"

"QUOTED IN EXISTS STATEMENT: This path DOES exist: c:\Program Files\Mozilla Firefox\firefox.exe"

QUOTE PART OF VALUE, UNQUOTED STATEMENT: This path DOES exist: "c:\Program Files\Mozilla Firefox\firefox.exe"

QUOTE PART OF VALUE, QUOTED STATEMENT: This path DOES exist: "c:\Program Files\Mozilla Firefox\firefox.exe"
The system cannot find the path specified.
QUOTE PART OF VALUE, QUOTED STATEMENT: This path does NOT exist: "c:\Program Files\Mozilla Firefox\firefox.exe"

So: no quotes in variable value, QUOTED IN EXISTS STATEMENT is a sane case on XP.

@hallvors
Copy link
Author

(Same on Win8 64bit)

@hallvors
Copy link
Author

Win 8.1:

No quotes added. Path is C:\Program Files (x86)\Nightly

"UNQUOTED: This path DOES exist: C:\Program Files (x86)\Nightly"
'Files' is not recognized as an internal or external command,
operable program or batch file.
"UNQUOTED: This path does NOT exist: C:\Program Files (x86)\Nightly"

"QUOTED IN EXISTS STATEMENT: This path DOES exist: C:\Program Files (x86)\Night
y"

QUOTE PART OF VALUE, UNQUOTED STATEMENT: This path DOES exist: "C:\Program File
 (x86)\Nightly"


QUOTE PART OF VALUE, QUOTED STATEMENT: This path DOES exist: "C:\Program Files
x86)\Nightly"
'Files' is not recognized as an internal or external command,
operable program or batch file.
QUOTE PART OF VALUE, QUOTED STATEMENT: This path does NOT exist: "C:\Program Files (x86)\Nightly"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment