Quickie: Getting the path to a batch file from inside itself.


To get the path to a batch file from inside itself you can use the environment variable %~dp0

This is really handy if you want to use non-relative paths inside it.  Why would you ever use that?

I have an external hard drive that I keep my bitcoin wallet on.  I have a batch file on the drive that tells it to use the data files on the external hard drive.  Here's the code.

Bitcoin-QT.bat
@echo off
REM I Run the local bitcoin executable and load the data REM from the data subdirectory.
%~dp0bitcoin-qt.exe -datadir=%~dp0data
And that's that.

P.s. Before I get mugged for my bitcoin wallet, you should know that I keep less than one coin in it.  I'm not worth it.  Really!


Comments