asp 中常用的文件处理函数
程序员文章站
2022-05-18 11:37:44
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
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>
<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'所有自定义的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
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>
上一篇: 樊哙:汉朝开国将领 ,刘邦身边第一猛士
下一篇: 皇帝养尊处优,为什么寿命都不会太长呢?
推荐阅读
-
MySQL中的常用函数
-
在ASP.NET 2.0中操作数据之十八:在ASP.NET页面中处理BLL/DAL层的异常
-
ASP.NET中实现导出ppt文件数据的实例分享
-
在ASP.NET 2.0中操作数据之三十八:处理BLL和DAL的异常
-
Python中shutil模块的常用文件操作函数用法示例
-
sqlserver中通过osql/ocmd批处理批量执行sql文件的方法
-
Python中functools模块的常用函数解析
-
在ASP.NET 2.0中操作数据之十八:在ASP.NET页面中处理BLL/DAL层的异常
-
Node.js中.pfx后缀文件的处理方法
-
C#中执行批处理文件(*.bat)的方法代码