加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

用ASP获取文本文件的几个函数

发布时间:2023-07-11 14:54:52 所属栏目:Asp教程 来源:
导读:**************************************************

'函数名:FSOFileRead

'作 用:使用FSO读取文件内容的函数

'参 数:filename ----文件名称

'返回值:文件内容

'*****
**************************************************
 
'函数名:FSOFileRead
 
'作 用:使用FSO读取文件内容的函数
 
'参 数:filename ----文件名称
 
'返回值:文件内容
 
'**************************************************
 
function FSOFileRead(filename)
 
Dim objFSO,objCountFile,FiletempData
 
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
 
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
 
FSOFileRead = objCountFile.ReadAll
 
objCountFile.Close
 
Set objCountFile=Nothing
 
Set objFSO = Nothing
 
End Function
 
'**************************************************
 
'函数名:FSOlinedit
 
'作 用:使用FSO读取文件某一行的函数
 
'参 数:filename ----文件名称
 
' lineNum ----行数
 
'返回值:文件该行内容
 
'**************************************************
 
function FSOlinedit(filename,lineNum)
 
if linenum < 1 then exit function
 
dim fso,f,temparray,tempcnt
 
set fso = server.CreateObject("scripting.filesystemobject")
 
if not fso.fileExists(server.mappath(filename)) then exit function
 
set f = fso.opentextfile(server.mappath(filename),1)
 
if not f.AtEndofStream then
 
tempcnt = f.readall
 
f.close
 
set f = nothing
 
temparray = split(tempcnt,chr(13)&chr(10))
 
if lineNum>ubound(temparray)+1 then
 
exit function
 
else
 
FSOlinedit = temparray(lineNum-1)
 
end if
 
end if
 
end function
 
'**************************************************
 
'函数名:FSOlinewrite
 
'作 用:使用FSO写文件某一行的函数
 
'参 数:filename ----文件名称
 
' lineNum ----行数
 
' Linecontent ----内容
 
'返回值:无
 
'**************************************************
 
function FSOlinewrite(filename,lineNum,Linecontent)
 
if linenum < 1 then exit function
 
dim fso,f,temparray,tempCnt
 
set fso = server.CreateObject("scripting.filesystemobject")
 
if not fso.fileExists(server.mappath(filename)) then exit function
 
set f = fso.opentextfile(server.mappath(filename),1)
 
if not f.AtEndofStream then
 
tempcnt = f.readall
 
f.close
 
temparray = split(tempcnt,chr(13)&chr(10))
 
if lineNum>ubound(temparray)+1 then
 
exit function
 
else
 
temparray(lineNum-1) = lineContent
 
end if
 
tempcnt = join(temparray,chr(13)&chr(10))
 
set f = fso.createtextfile(server.mappath(filename),true)
 
f.write tempcnt
 
end if
 
f.close
 
set f = nothing
 
end function
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章