 rem #New: 08.06.2020/J.Fes
 rem #Doc: Checks if Users has ReadWrtie access to Directory
 rem #Doc: P1 = Disk / or root path
 rem #Doc: P2 = SubPath on Disk
 rem #Doc: P3 = EnvVar contains SubDir on success
 rem #Doc: If EnvVar P3 is defined no check is done
 rem #Exa: "DirChkCreate.cmd" D: "JobMgrL_T" JobMgr_RootL_DP

 if "%~3" equ "" goto :myEndError

 rem get Disk
 set DirChkCreate_D$tmp=%~1
 rem get Disk and path
 set DirChkCreate_DP$tmp=%~1\%~2

 rem
 if defined %~3 goto :myEnd
 rem exist Disk?
 if not exist "%DirChkCreate_D$tmp%" goto :myEnd
 set DirChkCreate_DP$tmpTest=%DirChkCreate_DP$tmp%\zzTempReadWrtieAccess%UserName%

 rem Check create Dir
 if not exist "%DirChkCreate_DP$tmpTest%" md "%DirChkCreate_DP$tmpTest%"
 rem Check delete SubDir
 if exist "%DirChkCreate_DP$tmpTest%" rd /q "%DirChkCreate_DP$tmpTest%"
 rem if delete SubDir OK then set
 if "%errorlevel%" equ "0" if not exist "%DirChkCreate_DP$tmpTest%" set %~3=%DirChkCreate_DP$tmp%
 goto :myEnd

:myEndError
 Echo ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----
 Color 04
 Echo Error an call...................: %0
 Echo ISSUE at leased one parameter...: is empty
 Echo #Value P1.......................: '%~1'
 Echo #Value P2.......................: '%~2'
 Echo #Value P3.......................: '%~3'
 Echo Please Check Call
 pause
 goto :myEnd

:myEnd
 set DirChkCreate_D$tmp=
 set DirChkCreate_DP$tmp=
 set DirChkCreate_DP$tmpTest=
 goto :eof

