Bat: Change working directory to directory of script


Sometimes you want a batch file to always run with the directory of the script as the working directory. Not whatever directory you ran it from.

@echo off
pushd %~dp0
do stuff

Here pushd changes the directory to %~dp0, which is the directory of the running batch script. popd returns to whatever it was when the script started running. Not sure if the last step is necessary, but there you go anyways 🙂