This is a class I wrote in the course of my study.
<script Runat=server language=vbscript>
' The ' ', ' ' ', ', ', ' ', ' ', ' ', ' ', ' ' '
' Version: V1.0 '
' Author: Vince '
"' Email:vince6799@hotmail.com '"
' Time: 2005-6-19 '
' Usage: instance. Del_file (file path) '
' Set delfile=new delfile_class '
' File path: file's physical path '
' Return value: '
'-1: File deletion succeeded '
' 1:fso component does not exist '
' 2: The specified file does not exist '
' 3: Specified file cannot be deleted '
' Desi: Descriptive information '
'''''''''''''''''''''''''''''''''''''''''''''''''
Class Delfile_class
Dim Version,verr,desi
Private Sub Class_Initialize
Version = "File deletion class V1.0"
Verr= "-1"
Desi= ""
End Sub
Private Sub Class_Terminate
Verr= "-1"
End Sub
Private function GetFileName (sfilepath)
Getfilename=right (Sfilepath,instrrev (Sfilepath, "\")-1)
End Function
Public Function Del_file (Sfilepath)
On Error Resume Next
Dim oFSO
Set Chk=new Check_obj_class
If Chk. Isobjinstalled ("Scripting.FileSystemObject") =true Then
Set oFSO = Server.CreateObject ("Scripting.FileSystemObject")
If ofso.fileexists (Sfilepath) Then
Ofso.deletefile Sfilepath,true
If 0=err Then
Verr= "-1" ' File deletion succeeded
Desi=getfilename (Sfilepath) & "File deletion succeeded"
Else
Verr= ' 3 ' specifies that the file cannot be deleted
Desi=getfilename (Sfilepath) & "file cannot be deleted"
End If
Else
Verr= ' 2 ' specifies that the file does not exist
Desi=getfilename (Sfilepath) & "file does not exist"
End If
Set ofso=nothing
Else
Verr= "1" FSO component does not exist
Desi= "FSO component does not exist"
End If
Del_file=verr
End Function
End Class
"" "to detect whether the server supports an object class '" "" ""
' Version: V1.0 '
' Author: Vince '
"' Email:vince6799@hotmail.com '"
' Time: 2005-6-19 '
' Usage: instance. Isobjinstalled (object name) '
' Set chk=new check_obj_class '
' Object name: Detected object names '
' Return value: '
' True: Support '
' false: ' does not support '
'''''''''''''''''''''''''''''''''''''''''''''''''
Class Check_obj_class
Function isobjinstalled (strclassstring)
On Error Resume Next
isobjinstalled = False
ERR = 0
Dim Xtestobj
Set xtestobj = Server.CreateObject (strclassstring)
If 0 = Err Then isobjinstalled = True
Set xtestobj = Nothing
ERR = 0
End Function
End Class
</SCRIPT>