Code:
Break On


Go C:
cd "\temp"

$iLimit=10
$sResult=udfPipe('"'+%COMSPEC%+'" /C dir /a-d /o-d /b')
If @ERROR
"Could not get files. Error is:" ?
"["+@ERROR+"] "+@SERROR ?
"Extended error: " ?
$sResult[1] ?
Else
For Each $sFile in Split($sResult[0],@CRLF)
If $sFile
If $iLimit
"Will not delete file "+$sFile+@CRLF
$iLimit=$iLimit-1
Else
"Will delete file "+$sFile+@CRLF
EndIf
EndIf
Next
EndIf

; Execute a command and return output and error streams
; This code adapted from Chris S. WshPipe() http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82578
Function udfPipe($sCommand)
Dim $oExec
Redim $udfPipe[2]

$oExec = CreateObject("WScript.Shell").Exec($sCommand)
If Not VarType($oExec)=9 $udfPipe[1]=@SERROR Exit @ERROR EndIf

$udfPipe[0] = $oExec.StdOut.ReadAll
$udfPipe[1] = $oExec.StdErr.ReadAll

Exit $oExec.ExitCode
EndFunction ;}}}