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.
标签:902,Get,CMD,batch,echo,file,directory,dp0 From: https://www.cnblogs.com/alex-bn-lee/p/17753717.html