在批处理脚本上,与%~dp0
. 问题是,在我的脚本的某些部分,%~dp0
返回它应该返回的内容,即包含正在运行的脚本的文件夹的驱动器的完整路径(这里:'C:\Data\name\App\App\' )。在代码的其他一些部分,%~dp0
只返回包含脚本的驱动器(这里:'C:\')。
这是我的脚本(有史以来的第一个批处理脚本:D):
@ECHO OFF
ECHO.
:: run the script with the command new-built.bat /all -arch x86 -config release
SETLOCAL EnableDelayedExpansion
SET options=arch version config
SET what_to_build=all lib
:: the three following lines returns what is expected
echo %%~dp0 is returning : %~dp0
echo %%~p0 is returning : %~p0
echo %%~d0 is returning : %~d0
echo The absolute path to this script is : %~dp0%0
:: read what to build, ie all or lib only
FOR %%i in (%what_to_build%) do if %1==/%%i (
SHIFT
GOTO %%i
)
::the following sections (:readoptions and :optlp) work together to collect the options entered in the command, used to launch this script. It saves the values the two arrays "options" and "what_to_build" array
:readoptions
echo Entered the read options label
rem -- initialises variables arch, version and config with empty string
FOR %%i IN (%options% badoptions) DO (SET %%i=)
:optlp
echo Entered the read options loop
SET _parm1=%1
IF NOT DEFINED _parm1 GOTO :END
IF DEFINED _parm1 FOR %%i IN (%options%) DO IF .%_parm1%==.-%%i SET %%i=%2
IF DEFINED %%i shift&shift&(SET _parm1=)
IF DEFINED _parm1 SET badoptions=%badoptions% %1&SHIFT
GOTO :optlp
:all
echo Entered the all label ...
CALL :readoptions %*
echo About to build complete app for x86 in release config
set CYGWIN_DIR="%~dp0"
:: I want this line to return "C:\Data\name\App\App\" without quotes, but it's returning "C:\"
echo Cygwin dir (not returning what I want): %CYGWIN_DIR%
rem build lib
call %~dp0\build_scripts\build_lib_x86.bat
rem build the Visual Studio Solution
start "Build App x86 - release config" /W "%~dp0%build_scripts\build_app_x86_release.bat"
goto :end
:END
echo Program is done
endlocal
这是我得到的痕迹:
%~dp0 is returning : C:\Data\name\App\App\
%~p0 is returning : \Data\name\App\App\
%~d0 is returning : C:
The absolute path to this script is : C:\Data\name\App\App\new-build.bat
Entered the all label ...
Entered the read options label
Entered the read options loop
Entered the read options loop
Entered the read options loop
Entered the read options loop
Entered the read options loop
Entered the read options loop
Program is done
About to build complete app for x86 in release config
Cygwin dir (not returning what I want) : "C:\"
The system cannot find the path specified.
Program is done
一定有什么事情发生了,我错过了。任何帮助将不胜感激。
最好的