前往顾页
以后地位: 主页 > 收集编程 > Asp实例教程 >

FSO点窜文件函数试用体例相接

时候:2010-05-14 23:43来源:知行网www.zhixing123.cn 编辑:麦田守望者

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 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 Linecontent&chr(13)&chr(10)
f.close
set f = 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 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
'查抄文件内容是不是空的函数
Function FSOFilenell(filename)
dim myfso,myread
set myfso=createobject("scripting.filesystemobject")
set myread=myfso.opentextfile(server.mappath(filename),1,0)
if myread.atendofstream then
FSOFilenell=0
else
FSOFilenell=1
end if
myread.Close
Set myread=Nothing
Set myfso = 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
'天生文件
Function FSOcreate(filename)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
set f = fso.CreateTextFile(server.mappath(filename),true)
set f = nothing
set fso = nothing
End Function
'查抄是不是有文件
Function FSOfile(filename)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
f=server.MapPath(filename)
if fso.FileExists(f) then
FSOfile=1
else
FSOfile=0
end if
set f = nothing
set fso = nothing
End Function
'删失落文件
Function FSOdel(filename)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
f=server.MapPath(filename)
if fso.FileExists(f) then
fso.DeleteFile f,true
end if
set f = nothing
set fso = nothing
End Function

------分开线----------------------------
标签(Tag):ASP函数
------分开线----------------------------
保举内容
猜你感兴趣