Class for ASP file deletion

Source: Internet
Author: User

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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.