I think the easiest way is to check if it exists, and then join it if it does, or just write to it if it is not. From your tags, I assume that you are trying to do this from a batch file. This page seems to contain an example that fits you perfectly:
IF "%PATH%" == "" GOTO NOPATH :YESPATH @ECHO The PATH environment variable was detected. PATH=C:\DOS;%PATH% GOTO END :NOPATH @ECHO The PATH environment variable was NOT detected. PATH=C:\DOS; GOTO END :END
This batch code will add C: \ DOS to the path, just replace it with what you want to use. And, of course, you might want to delete echo lines or turn off alltogether echoes if you do not want messages to be displayed.
source share