none
In Visual studio command prompts batch fiel ? I see %~dp0bin\vcvars32.bat". What does "%~dp0bin" resolve to ? and How ?

    Question

  • In Visual studio command prompts batch fiel ? I see %~dp0bin\vcvars32.bat".    What does "%~dp0bin" resolve to ? and How ? I am actually calling vcvars32.bat file from my batch file. I am wondering what does "%~dp0bin"  mean  ?
    Wednesday, July 01, 2009 5:49 PM

Answers

  • Hi,

    Actually it is "%~dp0" and "bin".

    The %~dp0 macro in a batch file expands to the full path where the batch file lives. So %~dp0bin expands to something like "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin", if the batch file is stored in the VC folder. And if you copy the batch file to D:\ and run it, %~dp0bin will become "D:\bin".

    Hope this makes it clear.

    Regards,

    Jie
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    Thursday, July 02, 2009 8:31 AM
    Moderator

All replies

  • Hi,

    Actually it is "%~dp0" and "bin".

    The %~dp0 macro in a batch file expands to the full path where the batch file lives. So %~dp0bin expands to something like "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin", if the batch file is stored in the VC folder. And if you copy the batch file to D:\ and run it, %~dp0bin will become "D:\bin".

    Hope this makes it clear.

    Regards,

    Jie
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    Thursday, July 02, 2009 8:31 AM
    Moderator
  • Hi

    thanks for your reply. Will I be able to use the same syntax in my batch files to access the path ?
    Sunday, July 12, 2009 9:46 PM
  • Will I be able to use the same syntax in my batch files to access the path ?

    Yes you can.

    Try it by creating a simple test.cmd file like this:

    @echo off
    
    echo The path where this batch file lives: %~dp0
    pause
    
    @echo on

    Thanks,

    Jie
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    Monday, July 13, 2009 2:23 AM
    Moderator
  • I'm sorry to chime in, yet I was just back engineering a .BAT File from Enterprise Library 5.0 and came across this same exact question:  What is %~dp0 (You seemed to think from above it also had bin in it too).

    This is exactly the kind of thing that makes me hate, and I mean hate some of the more pointy head command line people who think this kind of thing is okay.  In my humble opinion, anything added to a script language, macro language, programming language, etc, should be logical in its presentation and never obscure if it is done to represent something.  How in the ____ is somebody supposed to know what %dp0 means?  Does this really save over this:  %CurrWorkDirMacro?  This type of ____ should never be tolerated as it is confusing, difficult to remember, and stupid.  I have my own thoughts on what dp really stands for and that is dumb punter!

    Tuesday, July 27, 2010 6:34 PM
  • Using batch parameters explains this better.
    Jie Wang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

     
    Thursday, January 13, 2011 4:21 AM
    Moderator