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%

posted @ 2020-01-06 10:21  随时静听  阅读(1114)  评论(0编辑  收藏  举报