Change to the directory a batch file is in

A very old blog entry…

The Old New Thing : Capturing the current directory from a batch file.

… but once again Raymond Chen’s fantastic blog answers a handy question (in the comments) – how do you change to the directory a batch file is in…


for /f %%i in ("%0") do set curpath=%%~dpi
cd /d %curpath%

This entry was posted in programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>