Take the 2-minute tour ×

I see the ':~' symbols used pretty often in BAT files, I presume it gets a character at a position, but I couldn't find any confirmation of this, nor on how/when to use it (it appears it can get a range as well).

Please if you could shed some light on this, thanks.

SET STRING=C:\MyDocuments\
IF "%STRING:~-1%"=="\" SET STRING=%STRING:~0,-1%

Also should %%A:~-1 work? or would I need to enclose it in ""?

share|improve this question

1 Answer 1

up vote 1 down vote accepted


help set 

in the commandline and you'll get a full description. Some is also documented in the help of the for command. So help for will give you additional information.

This is part of the output of the "help set" command:

May also specify substrings for an expansion.


would expand the PATH environment variable, and then use only the 5
result.  If the length is not specified, then it defaults to the
negative, then the number used is the length of the environment variable
value added to the offset or length specified.


would extract the last 10 characters of the PATH variable.


share|improve this answer
thank you! forgot about help command too haha –  user1229895 Apr 18 '12 at 7:07

Your Answer


