First, you need to set up a one-line file with the partial command
with no carriage return (CR) or linefeed (LF) at the end (this can be
done with COPY CON by pressing CTRL+Z after the equal sign [=] and
The file would look like this on the screen:
C:\>COPY CON INIT.TXT
The following steps can be issued from the MS-DOS command prompt or from
within a batch file:
• Search for a single directory entry and place the results in a text
dir | find "dos" > textfile
• Append the two files into one batch file using the COPY command as
copy init.txt+textfile varset.bat
• Place the contents of the text file in a variable by running
VARSET.BAT sets an environment variable equal to the directory entry found
earlier. This allows the environment variable to be used as a replaceable
parameter in later batch files. VARSET.BAT can be called from the command
prompt or from within another batch file.
NOTE: This process works for directory names only if MS-DOS 5.0 or 6.0 is
being used. Under MS-DOS 5.0 and 6.0, the /B switch must be used when you
are searching for a directory name. The following is an example of
searching for a directory under MS-DOS 5.0 or 6.0.
dir /b | find "dos5" > textfile
NOTE: There is still a 127-character limit to the length of this variable,
which includes the variable name and equal sign (=).