What is that called when you use MyVar:~0,-1 and the like so I can study how it works?
It's called (among other things) "string slicing" or "extracting substrings".
%AttachmentList:~0,-1% is saying don't skip any characters from beginning of variable and do not read last 1 character of variable?
The full syntax for specifying a substring (in this example %string% is the full string) is like this:
%string:~A,B%
A is the first character to take - it is the
offset from the start, counting from 0 (not 1, notice).
B specifies the length. if B is a positive number, it means the number of characters to take. If B is a negative number, it means take up to the character which is B characters from the end, so if B is -1 it means take characters up to the last but one.
So if %string% is abcde then
%string:~0,2% is ab
%string:~2,2% is cd
%string:~0,-1% is abcd
There is a variation of this syntax which is a little complicated. If you only specify one number e.g %string:~X%
Then:
If the number is positive, then take from the character whose zero-based offset is X up to the end of the string so
%string:~1% would be bcde
If the number is negative, take the last X characters from the string so
%string:~-2% would be de
From the SET documentation:
If the length is not specified, then it defaults to the
remainder of the variable value. If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.
You can fool about with all this at the prompt
c:\>set string=abcde
c:\>echo %string:~0,2%
ab
c:\>echo %string:~2,2%
cd
c:\>echo %string:~0,-1%
abcd
c:\>echo %string:~1%
bcde
c:\>echo %string:~-2%
de
c:\>
also note when the first number (of two) is negative, you count back from the end (starting at 1)
c:\>echo %string:~-3,1%
c
c:\>echo %string:~-3,2%
cd
c:\>echo %string:~-1,1%
e
c:\>echo %string:~-2,2%
de
c:\>echo %string:~-2,1%
d
I think I have covered most of it above, you can experiment yourself to get the hang of it, you seem the type! Unfortunately all too rare.
I am sure you will appreciate that a substring expression of the form %string:~A,B% is itself a variable and as such you can use it in various ways just like any other:
(This is not an exhaustive list!)
Echo directly to the console or a fileecho %string:~0,2%
echo The first two characters of %string% are %string:~0,2% > textfile.txt
Assign the substring to another stringset newstring=%string:~-4,2%
Test in an IF statementIF "%string:~-4,2%"=="bc" bla bla bla
Convert the main string into a substring of itselfset string=%string:~-4,2%
... and so on
I keep trying to look up arguments like that and I can't find them for the life of me =/
There is quite a good explanation in the help for SET which you can access by typing SET /? in a console window. Otherwise, search the web.
A really good source of information and (often) illumination is the Usenet group alt.msdos.batch.nt, which is available in Google Groups. It's searchable and you'd be amazed what you can pick up by using it intelligently.