This script is being written to wipe a bunch of temp directories in SAFE mode. My problem is that I'm having a hard time instituting error checking... the script actually works but the messages are misleading and I want them to be accurate. Case and point: the second DirFileWipe() called wipes the temp folder under C:\Windows\Temp but when I'm logged in as a normal user and the script gets access denied, my script still reports as executing successfully. Can anyone suggest how to implement error checking to account for that? @ERROR doesn't seem to be reporting anything... =/

Code:
Break ON
$ = SetOption("WrapAtEOL","ON")

? "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
? "!! ENSURE THIS SCRIPT IS BEING RUN FROM SAFE MODE !!"
? "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + @CRLF

? "Determining OS Type... "

SELECT
CASE @PRODUCTTYPE = "Windows XP Home Edition" OR @PRODUCTTYPE = "Windows XP Professional"
? @PRODUCTTYPE + @CRLF + @CRLF
$path = %SystemDrive% + "\Temp"
DirFileWipe($path)

$path = %WinDir% + "\Temp"
DirFileWipe($path)

CASE @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows 2000 Server" OR @PRODUCTTYPE = "Windows 2000 Domain Controller"
? "This script is only configured for Windows 2000/XP"

ENDSELECT

Sleep 15

EXIT





function DirFileWipe($path)

IF EXIST ($path)
? "- Wiping temp folder: " + $path
$DirList = DirList($path,4+2+1)
FOR EACH $x in $DirList
? @ERROR
DEL $x /h
NEXT

$DirList2 = DirList($path,4+2+1)
FOR EACH $x in $DirList2
SHELL "%COMSPEC% /c RD /S/Q $x"
? @SERROR
NEXT

? "- $path was wiped successfully..." + @CRLF
ELSE
? "- $path did not exist..."
ENDIF

endfunction

function dirlist($dirname, optional $options)
dim $filename, $counter, $filepath, $mask
dim $list, $sublist, $subcounter

$counter=-1

$dirname=trim($dirname)
if $dirname=''
$dirname=@CURDIR
endif
if right($dirname,1)='\'
$dirname=left($dirname,len($dirname)-1)
endif
if getfileattr($dirname) & 16
$mask='*.*'
else
$mask=substr($dirname,instrrev($dirname,'\')+1)
$dirname=left($dirname,len($dirname)-len($mask)-1)
endif

redim $list[10]
$filename=dir($dirname+'\'+$mask)
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
select
case (getfileattr($dirname+'\'+$filename) & 16)
if $options & 1
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'
else
$list[$counter]=$filename+'\'
endif
endif
if ($options & 4)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
case ($options & 2)
$counter=$counter+1
$list[$counter]=$dirname+'\'+$filename
case 1
$counter=$counter+1
$list[$counter]=$filename
endselect
if $counter mod 10
redim preserve $list[$counter+10]
endif
endif
$filename = dir('')
loop

if $counter+1
redim preserve $list[$counter]
else
$list=''
endif

if $mask<>'*.*' and ($options & 4)
$filename=dir($dirname+'\*.*')
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
if (getfileattr($dirname+'\'+$filename) & 16)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
endif
$filename = dir('')
loop
endif

if $counter+1
redim preserve $list[$counter]
else
$list=''
endif

$dirlist=$list
endfunction