服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - ASP教程 - asp 中常用的文件处理函数

asp 中常用的文件处理函数

2019-11-01 12:52asp教程网 ASP教程

asp 中处理文件上传以及删除时常用的自定义函数

  1. <%  
  2. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  3. '所有自定义的VBS函数  
  4. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  5. function DeleteFile(Filename) '删除文件  
  6. if Filename<>"" then  
  7. Set fso = server.CreateObject("Scripting.FileSystemObject")  
  8. if fso.FileExists(Filename) then  
  9. fso.DeleteFile Filename  
  10. end if  
  11. set fso = nothing  
  12. end if  
  13. end function  
  14. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  15. function CreateDIR(byval LocalPath) '建立目录的程序,如果有多级目录,则一级一级的创建  
  16. on error resume next  
  17. LocalPath = replace(LocalPath,"\","/")  
  18. set FileObject = server.createobject("Scripting.FileSystemObject")  
  19. patharr = split(LocalPath,"/")  
  20. path_level = ubound(patharr)  
  21. for i = 0 to path_level  
  22. if i=0 then pathtmp=patharr(0) & "/" else pathtmp = pathtmp & patharr(i) & "/"  
  23. cpath = left(pathtmp,len(pathtmp)-1)  
  24. if not FileObject.FolderExists(cpath) then FileObject.CreateFolder cpath  
  25. next  
  26. set FileObject = nothing  
  27. if err.number<>0 then  
  28. CreateDIR = false  
  29. err.Clear  
  30. else  
  31. CreateDIR = true  
  32. end if  
  33. end function  
  34. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  35. function SaveRandFileName(byval szFilename) '根据原文件名生成新的随机文件名  
  36. randomize  
  37. 'ranNum=int(90000*rnd)+10000  
  38. 'if month(now)<10 then c_month="0" & month(now) else c_month=month(now)  
  39. 'if day(now)<10 then c_day="0" & day(now) else c_day=day(now)  
  40. 'if hour(now)<10 then c_hour="0" & hour(now) else c_hour=hour(now)  
  41. 'if minute(now)<10 then c_minute="0" & minute(now) else c_minute=minute(now)  
  42. 'if second(now)<10 then c_second="0" & second(now) else c_second=minute(now)  
  43. fileExt_a=split(szFilename,".")  
  44. fileExt=lcase(fileExt_a(ubound(fileExt_a)))  
  45.  
  46. SaveRandFileName=replace(replace(replace(now,":",""),"-","")," ","")&int(10*rnd)&"."&fileExt  
  47. 'GenerateRandomFileName = year(now)&c_month&c_day&c_hour&c_minute&c_second&"_"&ranNum&"."&fileExt  
  48. end function  
  49. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  50. function jaron_replacer(strContent,start_string,end_string,replace_string)  
  51. 'CMS替换函数:源字符串,前部分,后部分,替换成的字符  
  52. '返回被替换后的字符串  
  53. jaron_replacer = replace(strContent,mid(strContent,instr(strContent,start_string),instr(strContent,end_string)+len(end_string)-1),replace_string)  
  54. end function  
  55. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  56. function replaceplus(strContent,start_string,end_string,replace_string)  
  57. '文档中,将所有开始,结束之间的所有字符删除  
  58. on error resume next  
  59. MARKCOUNTS = ubound(split(strContent,start_string))  
  60. PRESTRING = strContent  
  61. for i=0 to MARKCOUNTS  
  62. STARTMARK=instr(1,PRESTRING,start_string,1)  
  63. if STARTMARK=0 then exit for  
  64. COMPMARK=instr(1,PRESTRING,end_string,1) + len(end_string)  
  65. VerString=mid(PRESTRING,STARTMARK,COMPMARK - STARTMARK)  
  66. PRESTRING = replace(PRESTRING,VerString,replace_string)  
  67. next  
  68. replaceplus = PRESTRING  
  69. if err.number<>0 then err.Clear  
  70. end function  
  71. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  72. %>  

延伸 · 阅读

精彩推荐