Get Directory Path of an executing Batch file

Might not be needed for most of you out there that don’t use Batch files but what the heck.

So I was writing this simple app that will capture all my DLL and EXE files into a batch files to register and unregister them…. Please don’t ask me why (You can ask the QA team).

And one issue I found that if you run the batch file from a different folder was that is will execute the content of the batch file on the current working folder E.g batch file runs from C:\SomeFolder\ but you are in  C:\SomeOtherFolder\

So a simple addition at the beging of the batch file will return move to the correct folder.
Simply add “cd /d %~dp0” to the batch file and the execution will run on the folder.

Found this online (Some say he is wanted by the CIA, and that if he could be bothered, he could crack the Da Vinci code in 43 seconds. All we know is, he’s called The Stig. I don’t have The Stig’s number so I use Google).
Source – Linky

This entry was posted in Development, From Other Sites, Scripting and tagged , , , , . Bookmark the permalink.