windowspathbatch-file64-bitparentheses

Windows x64 & "parenthesis in path" batch file problem


Windows x64 versions contain folders named with parenthesis like \Program Files (x86) and this breaks a batch file I use. An example of a problem line:

for %%c in (%path%) do if exist "%%c\xyz.exe" set xyz=OK

i.e., when it reaches ) in (x86) it puts out an error message and exits...

How do I fix this?


Solution

  • Doesn't directly answer your question, but if you are trying to do what I thinking you are trying (which is make sure a file exists in the path) you can use something like the following in a batch file.

       @echo off
       for %%i in (xyz.exe) do set xyz=%%~$PATH:i
    
       if "%xyz%" == "" Goto NotFound
    
       Echo "Found"
       Goto TheEnd
    
    :NotFound
       Echo "Not found"
    
    :TheEnd