How to execute programs in the same directory as the windows batch file?

Jader Dias picture Jader Dias · Apr 28, 2010 · Viewed 95.7k times · Source

I have in the same folder a .bat and a .exe file. I couldn't call the .exe file from the .bat unless I put the full absolute path to it. Is there a way to don't specify the path?

Answer

Patrick Cuff picture Patrick Cuff · Apr 28, 2010

Try calling the .exe with %~dp0, like this: %~dp0MyProgram.exe.

%0 contains the full path to the called .bat file.

~dp says to get the drive and path, including trailing \.