bat获取当前目录和上级目录

@echo off

set currPath=%~dp0

set parentPath=

set parentPaths=

:begin

FOR /F "tokens=1,* delims=\" %%i IN ("%currPath%")  DO (set front=%%i)

FOR /F "tokens=1,* delims=\" %%i IN ("%currPath%")  DO (set currPath=%%j)



if not "%parentPath%" == "" goto gotJpdaOpts


:gotJpdaOpts


if "%parentPath%%front%\"=="%~dp0" goto end

set parentPath=%parentPath%%front%\

if "%parentPath:~-1%" == "\"  set  parentPaths=%parentPath:~0,-1%



goto begin


:end

echo %parentPath%%front%

echo %parentPath%

echo %parentPaths%

pause

猜你喜欢

转载自blog.csdn.net/m0_37137902/article/details/126619826