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