F
Frank B Denman
Hi Folks,
I'm getting into trouble in a batch file when I set a variable name that begins with a number. I'm
hoping somebody can help me understand why.
This batch file works just fine:
-------------------------------------------
SET A_FOLDER=D:\Temp\test\Able
SET B_FOLDER=D:\Temp\test\Baker
SET C_FOLDER=D:\Temp\test\Charley
SET _4C_FOLDER=D:\Temp\test\4_Charley
SET DIR_OUTPUT=D:\Temp\test\Delta\Appended_Dir_List.txt
::
dir "%A_FOLDER%">"%DIR_OUTPUT%"
dir "%B_FOLDER%">>"%DIR_OUTPUT%"
dir "%C_FOLDER%">>"%DIR_OUTPUT%"
dir "%_4C_FOLDER%">>"%DIR_OUTPUT%"
--------------------------------------------
However, if I lose the leading underscore on the fourth variable, so that the batch file looks like
this:
--------------------------------------------
SET A_FOLDER=D:\Temp\test\Able
SET B_FOLDER=D:\Temp\test\Baker
SET C_FOLDER=D:\Temp\test\Charley
SET 4C_FOLDER=D:\Temp\test\4_Charley
SET DIR_OUTPUT=D:\Temp\test\Delta\Appended_Dir_List.txt
::
dir "%A_FOLDER%">"%DIR_OUTPUT%"
dir "%B_FOLDER%">>"%DIR_OUTPUT%"
dir "%C_FOLDER%">>"%DIR_OUTPUT%"
dir "%4C_FOLDER%">>"%DIR_OUTPUT%"
--------------------------------------------
The last line now fails. Here's the output at the command prompt:
---------------------------------------------
D:\Temp\test>dirlist
D:\Temp\test>SET A_FOLDER=D:\Temp\test\Able
D:\Temp\test>SET B_FOLDER=D:\Temp\test\Baker
D:\Temp\test>SET C_FOLDER=D:\Temp\test\Charley
D:\Temp\test>SET 4C_FOLDER=D:\Temp\test\4_Charley
D:\Temp\test>SET DIR_OUTPUT=D:\Temp\test\Delta\Appended_Dir_List.txt
D:\Temp\test>dir "D:\Temp\test\Able" 1>"D:\Temp\test\Delta\Appended_Dir_List.txt"
D:\Temp\test>dir "D:\Temp\test\Baker" 1>>"D:\Temp\test\Delta\Appended_Dir_List.txt"
D:\Temp\test>dir "D:\Temp\test\Charley" 1>>"D:\Temp\test\Delta\Appended_Dir_List.txt"
D:\Temp\test>dir "C_FOLDERDIR_OUTPUT"
Volume in drive D is Data
Volume Serial Number is 94B6-1DC6
Directory of D:\Temp\test
File Not Found
D:\Temp\test>
---------------------------------------------
The final dir command seems to have concatenated elements of the line immediately above it. I would
really like to understand why.
Thanks for your help!
Frank
Frank Denman
Denman Systems
(e-mail address removed)
[Please delete the "x" from my email address]
I'm getting into trouble in a batch file when I set a variable name that begins with a number. I'm
hoping somebody can help me understand why.
This batch file works just fine:
-------------------------------------------
SET A_FOLDER=D:\Temp\test\Able
SET B_FOLDER=D:\Temp\test\Baker
SET C_FOLDER=D:\Temp\test\Charley
SET _4C_FOLDER=D:\Temp\test\4_Charley
SET DIR_OUTPUT=D:\Temp\test\Delta\Appended_Dir_List.txt
::
dir "%A_FOLDER%">"%DIR_OUTPUT%"
dir "%B_FOLDER%">>"%DIR_OUTPUT%"
dir "%C_FOLDER%">>"%DIR_OUTPUT%"
dir "%_4C_FOLDER%">>"%DIR_OUTPUT%"
--------------------------------------------
However, if I lose the leading underscore on the fourth variable, so that the batch file looks like
this:
--------------------------------------------
SET A_FOLDER=D:\Temp\test\Able
SET B_FOLDER=D:\Temp\test\Baker
SET C_FOLDER=D:\Temp\test\Charley
SET 4C_FOLDER=D:\Temp\test\4_Charley
SET DIR_OUTPUT=D:\Temp\test\Delta\Appended_Dir_List.txt
::
dir "%A_FOLDER%">"%DIR_OUTPUT%"
dir "%B_FOLDER%">>"%DIR_OUTPUT%"
dir "%C_FOLDER%">>"%DIR_OUTPUT%"
dir "%4C_FOLDER%">>"%DIR_OUTPUT%"
--------------------------------------------
The last line now fails. Here's the output at the command prompt:
---------------------------------------------
D:\Temp\test>dirlist
D:\Temp\test>SET A_FOLDER=D:\Temp\test\Able
D:\Temp\test>SET B_FOLDER=D:\Temp\test\Baker
D:\Temp\test>SET C_FOLDER=D:\Temp\test\Charley
D:\Temp\test>SET 4C_FOLDER=D:\Temp\test\4_Charley
D:\Temp\test>SET DIR_OUTPUT=D:\Temp\test\Delta\Appended_Dir_List.txt
D:\Temp\test>dir "D:\Temp\test\Able" 1>"D:\Temp\test\Delta\Appended_Dir_List.txt"
D:\Temp\test>dir "D:\Temp\test\Baker" 1>>"D:\Temp\test\Delta\Appended_Dir_List.txt"
D:\Temp\test>dir "D:\Temp\test\Charley" 1>>"D:\Temp\test\Delta\Appended_Dir_List.txt"
D:\Temp\test>dir "C_FOLDERDIR_OUTPUT"
Volume in drive D is Data
Volume Serial Number is 94B6-1DC6
Directory of D:\Temp\test
File Not Found
D:\Temp\test>
---------------------------------------------
The final dir command seems to have concatenated elements of the line immediately above it. I would
really like to understand why.
Thanks for your help!
Frank
Frank Denman
Denman Systems
(e-mail address removed)
[Please delete the "x" from my email address]