Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When you run a batch script by dragging another file onto it, the location of the file being dragged onto the batch script is used as the path.

How can I reference a file that's in the same folder as the batch script?

share|improve this question
Is a batch script normally run as though it is in the folder that the file that is dropped on it is in? – viking Jun 16 '11 at 21:29
That seems to be the way it behaves, yes. – Acorn Jun 16 '11 at 21:48
up vote 1 down vote accepted

Assuming Windows cmd.exe: "%~dp0\otherfile"

Here %0 references the batch file, ~ causes any quotation marks to be removed from the value, dp means "disk letter and path".

See for /? for a full list of expansions. (They unfortunately only apply to numbered command-line arguments and for single-letter variables. To use such expansions with environment variables like %myfile%, you'll have to pass them to a subroutine with call :label.)

share|improve this answer
Fantastic, thanks for the explanation! – Acorn Jun 17 '11 at 13:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.