The answer actually depends on which version of Windows you are using. Also, since this is a batch file, you want to suppress questions like "Do you really want to delete X?", which will really confuse and frighten your end-user.
Here's a batch that should work on all versions of windows for you: redir.bat
@echo off
if %1.==. goto usage
if exist %1\nul goto deldir
goto newdir
::------------------------------------------------
:deldir
:: Determine if we are using Windows 2000 or XP
ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto xp-and-2000
ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto xp-and-2000
goto nt-and-older
:xp-and-2000
rd /s/q %1
goto newdir
:nt-and-older
deltree /y %1
::------------------------------------------------
:newdir
md %1
goto end
::------------------------------------------------
:usage
echo usage:
echo %0 DIRNAME
echo.
echo Deletes the directory named DIRNAME and everything in it if it exists!
echo Then creates a new directory named DIRNAME
echo.
:end
Hope this helps.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
Skill Endorsements: 8
It is always great to give a nice, complete example and to be completely ignored not only at the time the example was given, but also a full year later.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
Skill Endorsements: 8
Do you mean like
rd /q/s C:\DOCUME~1\John\Cookies
rd /q/s C:\DOCUME~1\Jill\Cookies
rd /q/s C:\DOCUME~1\Johann\Cookies
?
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
Skill Endorsements: 8
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
Skill Endorsements: 8