這是我在學習過程中寫的一個類。
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
'''''''''''''''''''檔案刪除類''''''''''''''''''''
''版本:V1.0 ''
''作者:Vince ''
''email:vince6799@hotmail.com ''
''時間:2005-6-19 ''
''用法:執行個體.Del_File(檔案路徑) ''
''Set delfile=NEW DelFile_class ''
''檔案路徑:檔案的實體路徑 ''
''傳回值: ''
''-1:檔案刪除成功 ''
''1:FSO組件不存在 ''
''2:指定檔案不存在 ''
''3:指定檔案無法刪除 ''
''desi:描述資訊 ''
'''''''''''''''''''''''''''''''''''''''''''''''''
class DelFile_class
Dim Version,verr,desi
Private Sub Class_Initialize
Version = "檔案刪除類 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" '檔案刪除成功
desi=getFileName(sFilePath)&"檔案刪除成功"
else
verr="3" '指定檔案無法刪除
desi=getFileName(sFilePath)&"檔案無法刪除"
end if
else
verr="2" '指定檔案不存在
desi=getFileName(sFilePath)&"檔案不存在"
End If
set oFSO=nothing
else
verr="1" 'FSO組件不存在
desi="FSO組件不存在"
end if
Del_File=verr
end function
end class
''''''''''檢測伺服器是否支援某一對象類'''''''''''
''版本:V1.0 ''
''作者:Vince ''
''email:vince6799@hotmail.com ''
''時間:2005-6-19 ''
''用法:執行個體.IsObjInstalled(對象名) ''
''Set chk=NEW Check_Obj_class ''
''對象名:檢測的對象名稱 ''
''傳回值: ''
''true:支援 ''
''false:不支援 ''
'''''''''''''''''''''''''''''''''''''''''''''''''
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>