How to get my own path in a batch-file.

M

microtiger

Default answer is %~dp0. And most times this will work fine. But there is a bug in cmd.exe which will prevent this from working correctly under certain circumstances if you use double quotes to call the batch. Double quotes are necessary if the name or path of the batch file contains spaces. So for convenience everybody adds double quotes on all filenames. I struggled very long with this bug. This example will show the bug: Create this batch file, name it "z z.cmd" and put it in a folder specified by %path% or f.ex. in C:\Windows. @echo off echo.%~x0. echo.%~dpnx0. goto :eo

Continue reading...
 
Back
Top Bottom