echo off
echo.
echo ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
echo ³ Delete a directory with all its files              ³
echo ³ By Prof. Timo Salmi, ts@chyde.uwasa.fi, 22-Jan-91  ³
echo ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
echo.

if "%1"=="" goto _help

rem Change the directory-name parameter to upper case
set _stash=%path%
path %1
set _dir=%path%
path %_stash%
set _stash=

rem Checks
if "%_dir%"=="\" goto _isroot
if not exist %_dir%\nul goto _notexist
if not exist %_dir%\*.* goto _nofiles

rem The deletion process
cd %_dir%
cd
echo Delete the files from directory %_dir%
del *.*
if exist *.* goto _err1
cd ..
echo Break to quit, any other key to remove directory %_dir%
pause > nul
rmdir %_dir%
if not exist %_dir%\nul echo Directory %_dir% has been deleted
goto _out

:_isroot
echo Deleting the root directory %_dir% is not allowed
goto _out

:_notexist
echo Directory %_dir% not found
goto _out

:_nofiles
echo No files in directory %_dir%
goto _out

:_err1
echo Warning: Some or all files in %_dir% still remain
echo Directory still exists
cd ..
goto _out

:_help
echo         Usage: DELDIR [DirectoryName]
echo.
echo      ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo      º Be extra careful with this one. º
echo      º See the contents and make sure  º
echo      º you understand what is done.    º
echo      ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
echo.
echo If you get an "Out of environment space" message, increase your
echo environment space by using shell configuration in config.sys:
echo Example: shell=c:\bin\command.com /e:1024 /p
echo.

:_out
set _dir=
echo on
