[902] Get the current file's directory of CMD batch scripts

发布时间 2023-10-10 09:10:35作者: McDelfino

In a batch file, you can use the %~dp0 special variable to get the directory of the currently executing batch file. Here's how you can do it:

@echo off
echo The directory of this batch file is: %~dp0

When you run this batch file, it will display the directory where the batch file is located.

Explanation:

  • %0 represents the name of the currently executing batch file.
  • %~dp0 extracts the drive and path from %0, which effectively gives you the directory of the batch file.

This is a common way to obtain the directory of the batch file within the batch script itself.