@echo off
setlocal disabledelayedexpansion
call :start %*
endlocal

:start
call "info" info
if errorlevel 1 exit %errorlevel%
rem del /q "%exedir%%project%%ext%" >nul 2>&1
del /q "%exedir%%project%.map" >nul 2>&1
del /q "%exedir%%project%.map.sorted" >nul 2>&1
del /q "%exedir%%project%.rsm" >nul 2>&1
del /q "%exedir%%project%.drc" >nul 2>&1
del /q "%exedir%.release" >nul 2>&1
del /s /q "%srcdir%Units\*.*" >nul 2>&1
echo All compiled units come here. They can be rebuilt any time using the build.bat >"Units\!_info.txt"
echo script, so you can delete any files in this directory whenever you like. >>"Units\!_info.txt"
del /s /q "%srcdir%*.~*" >nul 2>&1
del /s /q "%srcdir%*.dcu" >nul 2>&1
del /s /q "%srcdir%*.dsk" >nul 2>&1
del /s /q "%srcdir%*.drc" >nul 2>&1
del /q "%srcdir%%project%.rc.bak" >nul 2>&1
del /q "%srcdir%%project%.res.bak" >nul 2>&1
del /q "%srcdir%%project%.dproj.2007" >nul 2>&1
del /q "%srcdir%%project%.dproj.local" >nul 2>&1
del /q "%srcdir%%project%.identcache" >nul 2>&1
del /q "%srcdir%%project%.skincfg" >nul 2>&1
del /q "%srcdir%%project%.stat" >nul 2>&1
del /q "%srcdir%%project%%ext%.log" >nul 2>&1
del /q "%srcdir%%project%.x64.dproj.local" >nul 2>&1
del /q "%srcdir%%project%.x64.identcache" >nul 2>&1
call :subdir "%srcdir%." "__history"
call :subdir "%srcdir%" "__recovery"
goto :eof

:subdir
if "%~1"=="" goto :eof
if "%~2"=="" goto :eof
pushd "%~1"
if exist "%~2" rd /s /q "%~2" >nul 2>&1
for /d %%i in (*) do call :subdir "%%i" "%~2"
popd
goto :eof
