setlocal enabledelayedexpansion
for /f "delims=" %%a in (%TempFile2%) do (
set a=%%a
set a=!a: =!
echo !a! >>%DataFile%
)
I understand that code looks for every "empty space" in tempfile2 data and sets it. What does this line mean ?
set a=!a: =!
Thanks
It's a basic pattern match and replace.
Here's the help from set /?
:
Environment variable substitution has been enhanced as follows:
%PATH:str1=str2%
would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2". "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output. "str1" can begin with an asterisk, in which case it will match
everything from the beginning of the expanded output to the first
occurrence of the remaining portion of str1.
The additional twist in your example is that the 'delayed expansion' syntax is being used, which uses the !
character as the environment variable expansion character instead of %
.
So the command set a=!a: =!
is removing all space characters from the contents of the variable a
.
Delayed expansion is needed (or at least makes something like this a bit easier) because of the way cmd.exe normally expands (then using the %
delimiter) the entire set of commands in the block enclosed by parens before executing any part of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With