Windows Batch. Append to PATH Environment Variable, when It Contains Spaces

My PATH contains spaces and I'm getting message ... was unexpected at this time

You need to quote the arguments to set.

Replace:

SET PATH=%MY_PATH%;%PATH%

With:

SET "PATH=%MY_PATH%;%PATH%"

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.