欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp 中常用的文件处理函数

程序员文章站 2022-10-27 20:54:37
asp 中处理文件上传以及删除时常用的自定义函数 <% '''''''''''''''''''''''''''''''''''''''''''''''''''''...
asp 中处理文件上传以及删除时常用的自定义函数

<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'所有自定义的vbs函数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function deletefile(filename) '删除文件
if filename<>"" then
set fso = server.createobject("scripting.filesystemobject")
if fso.fileexists(filename) then
fso.deletefile filename
end if
set fso = nothing
end if
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function createdir(byval localpath) '建立目录的程序,如果有多级目录,则一级一级的创建
on error resume next
localpath = replace(localpath,"\","/")
set fileobject = server.createobject("scripting.filesystemobject")
patharr = split(localpath,"/")
path_level = ubound(patharr)
for i = 0 to path_level
if i=0 then pathtmp=patharr(0) & "/" else pathtmp = pathtmp & patharr(i) & "/"
cpath = left(pathtmp,len(pathtmp)-1)
if not fileobject.folderexists(cpath) then fileobject.createfolder cpath
next
set fileobject = nothing
if err.number<>0 then
createdir = false
err.clear
else
createdir = true
end if
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function saverandfilename(byval szfilename) '根据原文件名生成新的随机文件名
randomize
'rannum=int(90000*rnd)+10000
'if month(now)<10 then c_month="0" & month(now) else c_month=month(now)
'if day(now)<10 then c_day="0" & day(now) else c_day=day(now)
'if hour(now)<10 then c_hour="0" & hour(now) else c_hour=hour(now)
'if minute(now)<10 then c_minute="0" & minute(now) else c_minute=minute(now)
'if second(now)<10 then c_second="0" & second(now) else c_second=minute(now)
fileext_a=split(szfilename,".")
fileext=lcase(fileext_a(ubound(fileext_a)))

saverandfilename=replace(replace(replace(now,":",""),"-","")," ","")&int(10*rnd)&"."&fileext
'generaterandomfilename = year(now)&c_month&c_day&c_hour&c_minute&c_second&"_"&rannum&"."&fileext
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function jaron_replacer(strcontent,start_string,end_string,replace_string)
'cms替换函数:源字符串,前部分,后部分,替换成的字符
'返回被替换后的字符串
jaron_replacer = replace(strcontent,mid(strcontent,instr(strcontent,start_string),instr(strcontent,end_string)+len(end_string)-1),replace_string)
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function replaceplus(strcontent,start_string,end_string,replace_string)
'文档中,将所有开始,结束之间的所有字符删除
on error resume next
markcounts = ubound(split(strcontent,start_string))
prestring = strcontent
for i=0 to markcounts
startmark=instr(1,prestring,start_string,1)
if startmark=0 then exit for
compmark=instr(1,prestring,end_string,1) + len(end_string)
verstring=mid(prestring,startmark,compmark - startmark)
prestring = replace(prestring,verstring,replace_string)
next
replaceplus = prestring
if err.number<>0 then err.clear
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>