The following code
introduces a space at the end of the value for var.
Assuming %%A="a", then using
should create a file named "a .txt" containing the value "a ". Note there are 2 spaces at the end of the content - one from the var assignment, and one because you have a space before your redirection.
If you drop the quotes from the redirection
then it should create a file named "a" containing the value "a .txt". Redirection can occur anywhere within a line. The parser assumes the file name stops at the space because it is not quoted. The rest of the line is treated as part of the content of the echo command.
You can eliminate the unwanted spaces by simply removing them from your code
Code: Select all
... DO SET var=%%A&CALL :next
...
echo %var%>"%var%.txt"
This should create a file named "a.txt" containing the value "a".
Another option is to use quotes in the assignment, and move the redirection to the front. Then extra spaces are ignored.
Code: Select all
... DO SET "var=%%A" & CALL :next
...
>"%var%.txt" echo %var%
Note that I still enclosed the file name in quotes. I recommend always doing so in case the value of var contains a space or special characters.
Dave Benham