alex_bn_lee

导航

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

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.

posted on 2023-10-10 09:03  McDelfino  阅读(3)  评论(0编辑  收藏  举报