You are currently offline, waiting for your internet to reconnect

Reading Text Files into MS-DOS Environment Variables

This article was previously published under Q66292
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
SUMMARY
This article describes the several steps needed to use the results ofa query (using the FIND filter) as a replaceable parameter in a one ormore batch files. A use for this would be to search for a specificfile and then perform some action on or with this file. The file couldthen be used in one or more batch files as a replaceable parameter.
MORE INFORMATION
First, you need to set up a one-line file with the partial command
   set varname=				
with no carriage return (CR) or linefeed (LF) at the end (this can bedone with COPY CON by pressing CTRL+Z after the equal sign [=] andpressing ENTER).

The file would look like this on the screen:
   C:\>COPY CON INIT.TXT   SET VARNAME=^Z				
The following steps can be issued from the MS-DOS command prompt or fromwithin a batch file:

  1. Search for a single directory entry and place the results in a text file.
          dir | find "dos" > textfile
  2. Append the two files into one batch file using the COPY command as follows:
          copy init.txt+textfile varset.bat
  3. Place the contents of the text file in a variable by running VARSET.BAT.
VARSET.BAT sets an environment variable equal to the directory entry foundearlier. This allows the environment variable to be used as a replaceableparameter in later batch files. VARSET.BAT can be called from the commandprompt or from within another batch file.

NOTE: This process works for directory names only if MS-DOS 5.0 or 6.0 isbeing used. Under MS-DOS 5.0 and 6.0, the /B switch must be used when youare searching for a directory name. The following is an example ofsearching 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 (=).
6.22 3.x 4.x 5.00 5.00a 6.00 6.20
Properties

Article ID: 66292 - Last Review: 05/10/2003 00:31:03 - Revision: 2.0

  • Microsoft MS-DOS 3.1
  • Microsoft MS-DOS 3.2 Standard Edition
  • Microsoft MS-DOS 3.21 Standard Edition
  • Microsoft MS-DOS 3.3 Standard Edition
  • Microsoft MS-DOS 3.3a
  • Microsoft MS-DOS 4.0 Standard Edition
  • Microsoft MS-DOS 4.01 Standard Edition
  • Microsoft MS-DOS 5.0 Standard Edition
  • Microsoft MS-DOS 6.0 Standard Edition
  • Microsoft MS-DOS 6.2 Standard Edition
  • Microsoft MS-DOS 6.21 Standard Edition
  • Microsoft MS-DOS 6.22 Standard Edition
  • KB66292
Feedback