手机
当前位置:查字典教程网 >编程开发 >ASP教程 >ASP FSO文件处理函数大全
ASP FSO文件处理函数大全
摘要:复制代码代码如下:

复制代码 代码如下:

<%

'建立文件夹函数

FunctionCreateFolder(strFolder)'参数为相对路径

'首选判断要建立的文件夹是否已经存在

DimstrTestFolder,objFSO

strTestFolder=Server.Mappath(strFolder)

SetobjFSO=CreateObject("Scripting.FileSystemObject")

'检查文件夹是否存在

IfnotobjFSO.FolderExists(strTestFolder)Then

'如果不存在则建立文件夹

objFSO.CreateFolder(strTestFolder)

EndIf

SetobjFSO=Nothing

Endfunction

'删除文件夹

FunctionDelFolder(strFolder)'参数为相对路径

strTestFolder=Server.Mappath(strFolder)

SetobjFSO=CreateObject("Scripting.FileSystemObject")

'检查文件夹是否存在

IfobjFSO.FolderExists(strTestFolder)Then

objFSO.DeleteFolder(strTestFolder)

endif

SetobjFSO=Nothing

Endfunction

'创建文本文件

FunctionCreatetextfile(fileurl,filecontent)'参数为相对路径和要写入文件的内容

SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")

Setfout=objFSO.CreateTextFile(Server.MapPath(fileurl))

fout.WriteLinefilecontent

fout.close

SetobjFSO=Nothing

EndFunction

'删除文件(适合所有文件)

FunctionDeltextfile(fileurl)'参数为相对路径

SetobjFSO=CreateObject("Scripting.FileSystemObject")

fileurl=Server.MapPath(fileurl)

ifobjFSO.FileExists(fileurl)then'检查文件是否存在

objFSO.DeleteFile(Server.mappath(fileurl))

endif

SetobjFSO=nothing

EndFunction

'建立图片文件并保存图片数据流

FunctionCreateimage(fileurl,imagecontent)'参数为相对路径和文件内容

SetobjStream=Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象,必须要ADO2.5以上版本

objStream.Type=1'以二进制模式打开

objStream.Open

objstream.writeimagecontent'将字符串内容写入缓冲

objstream.SaveToFileserver.mappath(fileurl),2'-将缓冲的内容写入文件

objstream.Close()'关闭对象

setobjstream=nothing

EndFunction

'远程获取文件数据

FunctiongetHTTPPage(url)

'OnErrorResumeNext

dimhttp

sethttp=Server.createobject("Microsoft.XMLHTTP")

Http.open"GET",url,false

Http.send()

ifHttp.readystate<>4then

exitfunction

endif

getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")

sethttp=nothing

IfErr.number<>0then

getHTTPPage="服务器获取文件内容出错"

Err.Clear

EndIf

Endfunction

FunctionBytesToBstr(body,Cset)

dimobjstream

setobjstream=Server.CreateObject("adodb.stream")

objstream.Type=1

objstream.Mode=3

objstream.Open

objstream.Writebody

objstream.Position=0

objstream.Type=2

objstream.Charset=Cset

BytesToBstr=objstream.ReadText

objstream.Close

setobjstream=nothing

EndFunction

'获取图片数据流

Functiongetpic(url)

onerrorresumenext

dimhttp

sethttp=server.createobject("MSXML2.XMLHTTP")'使用xmlhttp的方法来获得图片的内容

Http.open"GET",url,false

Http.send()

ifHttp.readystate<>4then

exitfunction

endif

getpic=Http.responseBody

sethttp=nothing

iferr.number<>0then

getpic="服务器获取文件内容出错"

err.Clear

Endif

EndFunction

'打开文件(文本形式)

FunctionOpenFile(fileurl)'文件相对路径

DimFilename,fso,hndFile

Filename=fileurl

Filename=Server.MapPath(Filename)

Setobjfso=CreateObject("Scripting.FileSystemObject")

Ifobjfso.FileExists(Filename)Then

sethndFile=objfso.OpenTextFile(Filename)

OpenFile=hndFile.ReadAll

Else

OpenFile="文件读取错误"

EndIf

SethndFile=Nothing

Setobjfso=Nothing

EndFunction

'获得文件的后缀名

functiongetFileExtName(fileName)

dimpos

pos=instrrev(filename,".")

ifpos>0then

getFileExtName=mid(fileName,pos+1)

else

getFileExtName=""

endif

endfunction

%>

【ASP FSO文件处理函数大全】相关文章:

ASP中字符与数字操作函数总结

在ASP处理程序时显示进度

ASP实现SQL备份、恢复

ASP中MsgBox函数和InputBox函数的使用

使用ASP控制指定站点解析脚本语言函数

asp 删除图片与文件函数

ASP采集入库生成本地文件的几个函数

asp 常用的字符串处理函数

ASP函数大全

ASP处理查询超时的解决函数

精品推荐
分类导航