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

Question
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)- Proposed as answer by Jay_WangMicrosoft employee, Moderator Tuesday, July 07, 2009 7:06 AM
- Marked as answer by Jay_WangMicrosoft employee, Moderator Tuesday, July 21, 2009 10:31 AM
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)- Proposed as answer by Jay_WangMicrosoft employee, Moderator Tuesday, July 07, 2009 7:06 AM
- Marked as answer by Jay_WangMicrosoft employee, Moderator Tuesday, July 21, 2009 10:31 AM
-
-
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) -
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!
-
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.