ASP檔案刪除的類

來源:互聯網
上載者:User

這是我在學習過程中寫的一個類。

<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>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.