Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Differences between %var and %~var  (Read 4937 times)

0 Members and 1 Guest are viewing this topic.

Dundir

    Topic Starter


    Rookie

    • Yes
  • Experience: Experienced
  • OS: Windows 7
Differences between %var and %~var
« on: March 20, 2011, 05:23:53 PM »
Anyone know what the differences are between those for batch files. I've seen some examples where they are used but haven't been able to figure out exactly what's going on as it seems different commands handle it differently (i.e. FOR). I'm trying to figure out a way for trimming out a portion of a string read in from a file using the for command. I'm just having trouble finding any documentation on the differences between %~var and %var, obviously there is a difference as running
Code: [Select]
set str="cmd politic"
echo.%str%
for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
echo.%str%
Works correctly in trimming " " out.
« Last Edit: March 20, 2011, 05:44:28 PM by Dundir »

Dundir

    Topic Starter


    Rookie

    • Yes
  • Experience: Experienced
  • OS: Windows 7
Re: Differences between %var and %~var
« Reply #1 on: March 20, 2011, 07:59:31 PM »
Thanks

Salmon Trout

  • Guest
Re: Differences between %var and %~var
« Reply #2 on: March 21, 2011, 11:14:36 AM »
I told you what the tilde ~ character did 4 days ago. It seems you don't read posts very carefully.

Quote from: Me, on 18 March
One of the variable modifiers you can use with FOR metavariables of the %%x type is the tilde ~ which removes enclosing quotes (if present).