exapmle
set BASE_DIR=%~dp0
echo "0 BASE_DIR path is %BASE_DIR%"
rem added double quotation marks to avoid the issue caused by the folder names containing spaces.
rem removed the last 5 chars(which means \bin\) to get the base DIR.
set BASE_DIR="%BASE_DIR:~0,-5%"
echo "1 BASE_DIR path is %BASE_DIR%"
结果
D:>log\bin\read.bat
“0 BASE_DIR path is D:\log\bin”
“1 BASE_DIR path is “D:\log””