What is the current directory in a batch file?

Aaron de Windt picture Aaron de Windt · Dec 12, 2010 · Viewed 615.7k times · Source

I want to create a few batch files to automate a program.

My question is when I create the batch file, what is the current directory? Is it the directory where the file is located or is it the same directory that appears in the command prompt, or something else?

Answer

JRL picture JRL · Dec 12, 2010

From within your batch file:

  • %cd% refers to the current working directory (variable)
  • %~dp0 refers to the full path to the batch file's directory (static)
  • %~dpnx0 and %~f0 both refer to the full path to the batch directory and file name (static).

See also: What does %~dp0 mean, and how does it work?