バッチスクリプトで、%~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
私が見逃している何かが起こっているに違いありません。どんな助けでも大歓迎です。
一番