Monday, March 16, 2009

Information on %~dp0

This macro is used to get the path of batch file.

It doesn't matter from where you are calling batch file it will return the path where the batch file is stored.

So if you put the following in a batch file, no matter what directory you are in when you run it, it will print the directory the batch file is in, and do a directory listing.

e.g. :
echo Batch file path is %~dp0
dir %~dp0

1 comment:

  1. If you write it like this
    set DIR=%~dp0

    then DIR variable will have directory address of current batch file.

    ReplyDelete