代码出处:如何获取bat的上一级目录、上两级目录...
https://blog.csdn.net/risun_lee/article/details/116039567- @echo off
-
- set CurrentPath=%~dp0
- set P1Path=
- set P2Path=
- set P3Path=
- set P4Path=
- set P5Path=
- :begin
- for /f "tokens=1,* delims=\" %%i in ("%CurrentPath%") do (set content=%%i&&set CurrentPath=%%j)
- if "%P1Path%%content%\" == "%~dp0" goto end
-
- set P5Path=%P4Path%
- set P4Path=%P3Path%
- set P3Path=%P2Path%
- set P2Path=%P1Path%
- set P1Path=%P1Path%%content%\
- goto begin
- :end
- echo BatPath=%~dp0
- echo P1Path=%P1Path%
- echo P2Path=%P2Path%
- echo P3Path=%P3Path%
- echo P4Path=%P4Path%
- echo P5Path=%P5Path%
- pause>nul
复制代码 运行结果,什么也看不到(不能执行)
是它的原来就有问题?还是我打字的过程中出错?谢谢 |