使用FSO修改文件特定内容的函数
functionFSOchange(filename,Target,String)
DimobjFSO,objCountFile,FiletempData
SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")
SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FiletempData=objCountFile.ReadAll
objCountFile.Close
FiletempData=Replace(FiletempData,Target,String)
SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
objCountFile.WriteFiletempData
objCountFile.Close
SetobjCountFile=Nothing
SetobjFSO=Nothing
EndFunction
使用FSO读取文件内容的函数
functionFSOFileRead(filename)
DimobjFSO,objCountFile,FiletempData
SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")
SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FSOFileRead=objCountFile.ReadAll
objCountFile.Close
SetobjCountFile=Nothing
SetobjFSO=Nothing
EndFunction
使用FSO读取文件某一行的函数
functionFSOlinedit(filename,lineNum)
iflinenum<1thenexitfunction
dimfso,f,temparray,tempcnt
setfso=server.CreateObject("scripting.filesystemobject")
ifnotfso.fileExists(server.mappath(filename))thenexitfunction
setf=fso.opentextfile(server.mappath(filename),1)
ifnotf.AtEndofStreamthen
tempcnt=f.readall
f.close
setf=nothing
temparray=split(tempcnt,chr(13)&chr(10))
iflineNum>ubound(temparray)+1then
exitfunction
else
FSOlinedit=temparray(lineNum-1)
endif
endif
endfunction
使用FSO写文件某一行的函数
functionFSOlinewrite(filename,lineNum,Linecontent)
iflinenum<1thenexitfunction
dimfso,f,temparray,tempCnt
setfso=server.CreateObject("scripting.filesystemobject")
ifnotfso.fileExists(server.mappath(filename))thenexitfunction
setf=fso.opentextfile(server.mappath(filename),1)
ifnotf.AtEndofStreamthen
tempcnt=f.readall
f.close
temparray=split(tempcnt,chr(13)&chr(10))
iflineNum>ubound(temparray)+1then
exitfunction
else
temparray(lineNum-1)=lineContent