@Echo off

 Call :Parse_All "%~dp0" CmdCurRoot
 set TitleTxt=PLMJobManager cleanup [%Date% %Time:~0,5%]
 title %TitleTxt%

 :Menue
 Color E0
 Echo.
 Echo --------------------------------------------------------------------------
 Echo %TitleTxt%
 Echo.
 Echo Start Root: %CmdCurRoot_DPnoPLast%\..
 Echo Delete    : ..*.bak ..*.tmp
 Echo.
 Echo  S  = Start CleanUp ..
 Echo  Q  = Quit (beendet dieses Menue)
 Echo.
 set doNext=
 set /P doNext= waehle Funktion:

 if /I "%doNext%"=="Q"   goto :MyEnd
 if /I "%doNext%"=="S"   call :DO_StartCleanUp

 goto :Menue

:DO_StartCleanUp
 Color A0
 Echo.
 REM  Echo List der geparsten Verzeichnisse:
 set toRun=del /s "%CmdCurRoot_DPnoPLast%\*.bak","%CmdCurRoot_DPnoPLast%\*.tmp"
 %toRun%
 goto :eof

:MyEnd
 goto :eof

rem ============================================================================
:Parse_All
 rem parst alle File Bezeichner aus
 rem "\" abschneiden
 set Parse_all$temp=%~dp1
 set Parse_all$temp=%Parse_all$temp:~0,-1%
 call :Parse_PLast %Parse_all$temp% %2_PLast %2_PLast2
 call :Parse_PathCutLastDir %~dp0 %2_DPnoPLast
 set %2_DP=%Parse_all$temp%
 set %2_D=%~d1
 rem "\" hinten und vorne abschneiden
 set Parse_all$temp=%~p1
 set Parse_all$temp=%Parse_all$temp:~1,-1%
 set %2_P=%Parse_all$temp%
 set %2_NE=%~nx1
 set %2_N=%~n1
 set %2_E=%~x1
 set %2_DPNE=%1
 set %2_DPN=%~dpn1
 set Parse_all$temp=
 goto :eof

:Parse_PLast
 rem parst den LetzenPath
 set %2=%~n1
 set %3=%~nx1
 goto :eof


:Parse_PathCutLastDir
 rem schneidet das letzte Verzeichniss Uebergeben path ab
 rem P1 = Name der Variablen
 rem P2 = der Übergebene Path
 rem Example : call :PathCutLastDir "%~dp0" MyVar_DP

 set PathCutLastDir$temp=%1
 set PathCutLastDir$temp=%PathCutLastDir$temp:"=%
 set PathCutLastDir$tempLastChar=%PathCutLastDir$temp:~-1%
 set PathCutLastDir$tempNoBacks=%PathCutLastDir$temp:~0,-1%

 if "%PathCutLastDir$tempLastChar%"=="\" (
   rem "\" abschneiden wenn vorhanden
   call :PathCutLastDirDo PathCutLastDir$tempRes %PathCutLastDir$tempNoBacks%
 ) else (
   rem
   call :PathCutLastDirDo PathCutLastDir$tempRes %PathCutLastDir$temp%
 )
 set PathCutLastDir$tempRes=%PathCutLastDir$tempRes:~0,-1%
 set %2=%PathCutLastDir$tempRes%
 set PathCutLastDir$temp=
 set PathCutLastDirDo$temp1=
 set PathCutLastDir$tempNoBacks=
 set PathCutLastDir$tempNoLastChar=
 set PathCutLastDir$tempLastChar=
 set PathCutLastDir$tempRes=
 goto :eof

:PathCutLastDirDo
 rem hiermit schneiden wir den Path ab
 rem echo.
 rem Echo P1=%1 P2=%2
 set PathCutLastDirDo$temp=%~dp2
 rem "\" abschneiden
 set PathCutLastDirDo$temp1=%PathCutLastDir$temp:~0,-1%
 set %1=%PathCutLastDirDo$temp%
 set PathCutLastDirDo$temp=
 set PathCutLastDirDo$temp1=
 goto :eof

