The substring syntax :~ is inserted between the opening and closing % signs that surround your variable.
Thus, instead of
%complete_variable_name%
,you have%complete_variable_name:~[chars-to-skip],[chars-to-collect]%
- if
[chars-to-skip]
is negative, then it starts from the end of the string - if
[chars-to-collect]
is negative, then it ends that many characters from the end of the string
C:> set filename=abcde.txt
C:> echo %filename%
abcde.txt
C:> echo %filename:~0,-3%
abcde.
C:> echo %filename:~-3,3%
txt
C:> set outname=%filename:~0,-4%.output
C:> echo %outname%
abcde.output