Rob van der Woude's Scripting Pages

The SET command: DOS exceptions

In DOS, any command line, or batch file line, executed by COMMAND.COM is limited to 127 characters.
That goes for the PATH too.
But sometimes you really need a path longer than that.
Try setting the path in CONFIG.SYS instead of AUTOEXEC.BAT:

SET PATH=....MORE..THAN..500..CHARACTERS....

By doing so, you can make your path as long as you like.
However, you cannot change the path later using batch files, since batch files will ignore all characters after the 127th.

Because of the difference between OS/2's and DOS' CONFIG.SYS, this trick will not work in OS/2 DOS sessions.

Use Marc Stern's XSET (Extended SET Instruction) if you really need to alter the long path later.

MS-DOS 6.22 and earlier versions

In "real" DOS, environment variable names should always be in upper case, otherwise the SET command cannot be used to manipulate them.

Try the SET command without any parameters from a DOS prompt in Windows 3.*/95 and you'll notice at least one variable name in lower case: windir
If you closed all your programs and saved your data you might try the command:

SET WINDIR=

With any other (upper case) variable this would result in removal of the variable from the environment. It wouldn't show up after typing SET without further parameters.
If that were the case I wouldn't have mentioned it here, of course. After typing SET you should still see the line:

windir=C:\WINDOWS

(provided Windows is installed on your C: drive).

Now try to read %windir% within a batch file: %windir% does not expand to C:\WINDOWS !

There is a way to read %windir%, (there always seems to be a way) which does require some redirection (of course :-).

@ECHO OFF
SET | FIND "windir=" > TEMP.BAT
ECHO SET WINDIR=%%2> WINDIR.BAT
CALL TEMP.BAT
DEL TEMP.BAT
DEL WINDIR.BAT
SET | FIND /I "WINDIR"

Running this batch file will display these two lines:

windir=C:\WINDOWS
WINDIR=C:\WINDOWS

So this leaves you with two windir variables, one in lower case and one in upper case. You can manipulate the uppercase WINDIR variable using SET, the lower case windir variable will remain unaltered whatever you try.

Marc Stern's XSET (Extended SET Instruction) can handle lower case variable names too.


page last uploaded: 2015-08-24, 21:07