bat获取父级路径
获取文件父级路径
set mysqlPath="C:\mysql-5.7.28-win32\bin\mysql.exe"
//获取父级目录,必须是后面无斜杠,默认处理后后面带有斜杠
for %%a in ("%sqlPath%") do (
set mysqlHome=%%~pda
)
echo %mysqlHome%
if "%mysqlHome:~-1%" equ "\" (
set mysqlHome=%mysqlHome:~0,-1%
)
echo %mysqlHome%
for %%a in ("%mysqlHome%") do (
set mysqlHome=%%~pda
)
echo %mysqlHome%
if "%mysqlHome:~-1%" equ "\" (
set mysqlHome=%mysqlHome:~0,-1%
)
echo %mysqlHome%