热门文章
 
fso操作文件 实例函数
利用FSO取得BMP,JPG
FileSystemObje
fso使用:drive 读取
fso:folder 文件系
fso:file 文件对象
scripting.Text
ASP实现结构化列举并查看某
Adodb.Stream
ASP 批量文件改名
 推荐文章
 
asp无组件读取图片文件信息
限制(禁用)FSO组件的方法
fso使用例子:创建文件夹
fso:file 文件对象
fso应用中的几个小函数
ASP FSO相关的一些例子
fso的一些特殊功能
FSO读取网站系统使用空间的
使用FSO修改文件夹的名称
fso复制文件夹所有内容和删
FSO操作文件系统代码
稻香老农的无组件上传类(完整
一个基于Jscript和fs
无惧 无组件上传完整代码
asp静态模版技术之标签参数
无组件上传文件被杀毒软件误报
 
你现在的位置:您现在的位置是: 中国ASP>>ASP教程>>fso组件
FSO操作文本的几个函数

使用FSO修改文件特定内容的函数
function FSOchange(filename,Target,String)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FiletempData = objCountFile.ReadAll
objCountFile.Close
FiletempData=Replace(FiletempData,Target,String)
Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
objCountFile.Write FiletempData
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function

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

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 


使用FSO读取文件某一行的函数


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 

 

使用FSO写文件某一行的函数


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 

 

使用FSO添加文件新行的函数


function FSOappline(filename,Linecontent)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),8,1)
f.write chr(13)&chr(10)&Linecontent
f.close
set f = nothing
end function 

 

读文件最后一行的函数


function FSOlastline(filename)
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))
  FSOlastline = temparray(ubound(temparray))
end if
end function 

 


相关信息:

fso操作文件 实例函数
利用FSO取得BMP,JPG,PNG,GIF文件信息
FileSystemObject对象成员概要
fso使用:drive 读取驱动器信息
fso:folder 文件系统
fso:file 文件对象
scripting.TextStream对象-fso读写文本
ASP实现结构化列举并查看某路径下所有文件

 

中国ASP技术 ASP.ORG.CN 版权所有 2004-2008