Clear_temporary_files.Asp
上传用户:qfkgdy
上传日期:2020-06-18
资源大小:1888k
文件大小:5k
源码类别:

手机WAP编程

开发平台:

ASP/ASPX

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <% 
  3. dim st 
  4. st=timer() 
  5. '************************************************************* 
  6. '*************搜索硬盘文件的类SearchFile ************* 
  7. '*************调用方法: ************* 
  8. '*************Set newsearch=new SearchFile '声明 ************* 
  9. '*************newsearch.Folder="F:+E:"'传入搜索源************* 
  10. '*************newsearch.keyword="汇编" '关键词************* 
  11. '*************newsearch.Search '开始搜索************* 
  12. '*************Set newsearch=Nothing '结束************* 
  13. '*************Copyright(c)醉雨梧桐小站 ************* 
  14. '*************http://btyz.51web.cn/ ************* 
  15. '************************************************************* 
  16. Class SearchFile 
  17. dim Folders '传入绝对路径,多路径使用+号连接,不能有空格 
  18. dim keyword '传入关键词 
  19. dim objFso '定义全局变量 
  20. dim Counter '定义全局变量,搜索结果的数目 
  21. '*****************初始化************************************** 
  22. Private Sub Class_Initialize 
  23. Set objFso=Server.CreateObject("Scripting.FileSystemObject") 
  24. Counter=0 '初始化计数器 
  25. End Sub 
  26. '************************************************************ 
  27. Private Sub Class_Terminate 
  28. Set objFso=Nothing 
  29. End Sub 
  30. '**************公有成员,调用的方法*************************** 
  31. Function Search 
  32. Folders=split(Folders,"+") '转化为数组 
  33. keyword=trim(keyword) '去掉前后空格 
  34. if keyword="" then 
  35. 'Response.Write("<font color='red'>关键字不能为空</font><br/>") 
  36. exit Function 
  37. end if 
  38. '判断是否包含非法字符 
  39. flag=instr(keyword,"") or instr(keyword,"/") 
  40. flag=flag or instr(keyword,":") 
  41. flag=flag or instr(keyword,"|") 
  42. flag=flag or instr(keyword,"&") 
  43. if flag then '关键字中不能包含/:|& 
  44. 'Response.Write("<font color='red'>关键字不能包含/:|&</font><br/>") 
  45. Exit Function '如果包含有这个则退出 
  46. end if 
  47. '多路径搜索 
  48. dim i 
  49. for i=0 to ubound(Folders) 
  50. Call GetAllFile(Folders(i)) '调用循环递归函数 
  51. next 
  52. 'Response.Write("共搜索到<font color='red'>"&Counter&"</font>个结果") 
  53. End Function 
  54. '***************历遍文件和文件夹****************************** 
  55. Private Function GetAllFile(Folder) 
  56. dim objFd,objFs,objFf 
  57. Set objFd=objFso.GetFolder(Folder) 
  58. Set objFs=objFd.SubFolders 
  59. Set objFf=objFd.Files 
  60. '历遍子文件夹 
  61. dim strFdName '声明子文件夹名 
  62. '*********历遍子文件夹****** 
  63. on error resume next 
  64. For Each OneDir In objFs 
  65. strFdName=OneDir.Name 
  66. '系统文件夹不在历遍之列 
  67. If strFdName<>"Config.Msi" EQV strFdName<>"RECYCLED" EQV strFdName<>"RECYCLER" EQV strFdName<>"System Volume Information" Then 
  68. SFN=Folder&""&strFdName '绝对路径 
  69. Call GetAllFile(SFN) '调用递归 
  70. End If 
  71. Next 
  72. dim strFlName 
  73. '**********历遍文件******** 
  74. For Each OneFile In objFf 
  75. strFlName=OneFile.Name 
  76. 'desktop.ini和folder.htt不在列取范围 
  77. If strFlName<>"desktop.ini" EQV strFlName<>"folder.htt" Then 
  78. FN=Folder&""&strFlName 
  79. Counter=Counter+ColorOn(FN) 
  80. End If 
  81. Next 
  82. '*************************** 
  83. '关闭各对象实例 
  84. Set objFd=Nothing 
  85. Set objFs=Nothing 
  86. Set objFf=Nothing 
  87. response.redirect "/images/time.gif"
  88. End Function 
  89. '*********************生成匹配模式*********************************** 
  90. Private Function CreatePattern(keyword) 
  91. CreatePattern=keyword 
  92. CreatePattern=Replace(CreatePattern,".",".") 
  93. CreatePattern=Replace(CreatePattern,"+","+") 
  94. CreatePattern=Replace(CreatePattern,"(","(") 
  95. CreatePattern=Replace(CreatePattern,")",")") 
  96. CreatePattern=Replace(CreatePattern,"[","[") 
  97. CreatePattern=Replace(CreatePattern,"]","]") 
  98. CreatePattern=Replace(CreatePattern,"{","{") 
  99. CreatePattern=Replace(CreatePattern,"}","}") 
  100. CreatePattern=Replace(CreatePattern,"*","[^\/]*") '*号匹配 
  101. CreatePattern=Replace(CreatePattern,"?","[^\/]{1}") '?号匹配 
  102. CreatePattern="("&CreatePattern&")+" '整体匹配 
  103. End Function 
  104. '**************************搜索并使关键字上色************************* 
  105. Private Function ColorOn(FileName) 
  106. dim objReg 
  107. Set objReg=new RegExp 
  108. objReg.Pattern=CreatePattern(keyword) 
  109. objReg.IgnoreCase=True 
  110. objReg.Global=True 
  111. retVal=objReg.Test(FileName) '进行搜索测试,如果通过则上色并输出 
  112. if retVal then 
  113. OutPut=objReg.Replace(FileName,"$1") '设置关键字的显示颜色 
  114. '***************************该部分可以根据需要修改输出************************************ 
  115. Dim objFSO '声明一个名称为 objFSO 的变量以存放对象实例 
  116. Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 
  117. objFSO.DeleteFile OutPut,True
  118. 'OutPut=""&OutPut&"<br/>" 
  119. 'Response.Write(OutPut) '输出匹配的结果 
  120. '*************************************可修改部分结束************************************** 
  121. ColorOn=1 '加入计数器的数目 
  122. else 
  123. ColorOn=0 
  124. end if 
  125. Set objReg=Nothing 
  126. End Function 
  127. End Class 
  128. '************************结束类SearchFile********************** 
  129. %> 
  130.  
  131. <% 
  132. dim keyword 
  133. keyword=Request.Form("keyword") 
  134. if keyword="" then keyword="temp"
  135. if keyword<>"" then 
  136. Set newsearch=new SearchFile 
  137. newsearch.Folders=server.mappath("imagestemp") 
  138. newsearch.keyword=keyword 
  139. newsearch.Search 
  140. Set newsearch=Nothing 
  141. 'response.Write("<br/>费时:"&(timer()-st)*1000&"毫秒") 
  142. end if 
  143. %>