使用fso修改文件特定內容的函數
FunctionFsochange(文件名,目標,字符串)
Dimobjfso,objcountfile,filetempdata
setObjfso = server.createobject(“ scripting.filesystemobject”)
setObjcountfile = objfso.opentextfile(server.mappath(filename),1,true)
filetempdata = objcountfile.readall
objcountfile.close
filetempdata =替換(filetempdata,target,string)
setObjcountfile = objfso.createTextfile(server.mappath(filename),true)
objcountfile.writefiletempdata
objcountfile.close
setObjcountfile =沒有
setObjfso =什麼都沒有
最終功能
使用fso讀取文件內容的函數
functionfsofileread(文件名)
Dimobjfso,objcountfile,filetempdata
setObjfso = server.createobject(“ scripting.filesystemobject”)
setObjcountfile = objfso.opentextfile(server.mappath(filename),1,true)
fsofileread = objcountfile.readall
objcountfile.close
setObjcountfile =沒有
setObjfso =什麼都沒有
最終功能
使用fso讀取文件某一行的函數
functionfsolinedIt(文件名,linenum)
ifineNum <1 thenexitFunction
Dimfso,f,temparray,tempcnt
setfso = server.createobject(“ scripting.filesystemobject”)
ifnotfso.fileexists(server.mappath(fileName))然後exeDfunction
setf = fso.opentextfile(server.mappath(filename),1)
ifnotf.atendofstreamthen
tempcnt = f.Readall
f.close
setf =沒有
temparray = split(tempcnt,chr(13)和chr(10))
ifineNum> ubound(temparray)+1
出口
別的
fsolinedit = temparray(linenum-1)
Endif
Endif
最終功能
使用fso寫文件某一行的函數
functionfsolinewrite(文件名,linenum,linecontent)
ifineNum <1 thenexitFunction
Dimfso,f,temparray,tempcnt
setfso = server.createobject(“ scripting.filesystemobject”)
ifnotfso.fileexists(server.mappath(fileName))然後exeDfunction
setf = fso.opentextfile(server.mappath(filename),1)
ifnotf.atendofstreamthen
tempcnt = f.Readall
f.close
temparray = split(tempcnt,chr(13)和chr(10))
ifineNum> ubound(temparray)+1
出口
別的
temparray(Linenum-1)= linecontent