@echo off

rem Beschreibung:
rem
rem Info zur Version:
rem Datum     Wer     Info
rem #Datum#   J.Fes   erserstellung

:Menue
 Color 8E
 call :DateTimeNowGet
 rem get BackUpDut
 set DirToBackup_DP=%~dpnx1
 set DirToBackup_Zip_DPNE=%DirToBackup_DP%-%DateTimeNowFileExt-YYYY-MM-DD_HH-mm%.zip
 set path=%~dp0;%Path%
 
 Echo --------------------------------------------------------------------------
 Echo DirToBackup_DP:      [%DirToBackup_DP%]
 Echo DirToBackup_Zip_DPNE:[%DirToBackup_Zip_DPNE%]
 Echo.
 Echo S  = Start Backup
 Echo E  = open Dir via Explorer 
 Echo Q  = Quit (No backup)
 Echo.
 set doNext=

 set /P doNext= waehle Funktion:

 Color A0
 if /I "%doNext%"=="Q"   goto :eof
 if /I "%doNext%"=="S"   call :DoBackupDirToZip
 if /I "%doNext%"=="E"   call :DoOpenDirViaExplorer
 goto :Menue

:DoOpenDirViaExplorer
   if exist "%DirToBackup_Zip_DPNE%" ( 
	  start "Explorer" Explorer /e,/select, "%DirToBackup_Zip_DPNE%"
	 ) else (
      start "Explorer" Explorer /e,/select, "%DirToBackup_DP%"
	 )	 
	
 goto :eof

:DoBackupDirToZip
  call "%~dp0Zip_DP.cmd" "%DirToBackup_DP%" "%DirToBackup_Zip_DPNE%"
 goto :eof

rem -- Standard Subroutines ---------------------
:PathCutLastDir
 rem schneidet das letzte Verzeichniss Uebergeben path ab
 rem P1 = Name der Variablen
 rem P2 = der Übergebene Path
 rem Example : call :PathCutLastDir EntwRoot_LP %~dp0
 rem Example : call :PathCutLastDir MyVar %~dp0

 set PathCutLastDir$temp=%2
 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 %1=%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


:DateTimeNowGet
 rem call :DateTimeNowGet
 rem Set File_LPNE=%DatRoot_LP%\MyName-%DateTimeNowFileExt%.txt
 if     "%time:~0,1%"==" " set time-h=0%time:~1,1%
 if not "%time:~0,1%"==" " set time-h=%time:~0,2%

 if     "%time:~3,1%"==" " set time-m=0%time:~4,1%
 if not "%time:~3,1%"==" " set time-m=%time:~3,2%

 set Date-Y=%Date:~6,4%
 set Date-M=%Date:~3,2%
 set Date-D=%Date:~0,2%
 set DateTimeNowFileExt=%Date-Y%-%Date-M%-%Date-D%-%time-h%-%time-m%
 set DateTimeNowFileExt-YYYY-MM-HH=%Date-Y%-%Date-M%-%Date-D%-%time-h%
 set DateTimeNowFileExt-YYYY-MM-DD_HH-mm=%Date-Y%-%Date-M%-%Date-D%_%time-h%-%time-m%
 goto :eof




