@echo off
REM - There are the following ways to determine the name of the dproj file:
REM - 1. It can be passed as %1 parameter
REM - 2. If __SetProjectName.cmd exists in the current directory, it gets called
REM -    and should set the %project% environment variable.
REM - 3. It is assumed that the current directory is also the project name (this is probably
REM -    the most common case).
REM - The project is returned in the environment variable %project%

setlocal

rem Has the project been passed as parameter?
set project=%1
if not "%project%"=="" goto projgiven
rem Is there a __SetProjectName.cmd which supposedly sets %project%?
if exist __SetProjectName.cmd call __SetProjectName.cmd
if not "%project%"=="" goto projgiven
rem Still no project, use the parent directory name to get it
call :GetLastDir %CD%
set project=%result%

:projgiven
endlocal & set project=%project%
rem echo project="%project%"
rem pause
goto :eof

:GetLastDir
rem extract path
setlocal
set directory=%1%
rem extract "filename" (= last directory of path)
call :LastItem %directory%
endlocal & set result=%result%
goto :eof

:LastItem
set result=%~n1%
goto :eof
