21. Read the last line of the file 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) &CHR (10))
Fsolastline = Temparray (UBound (Temparray))
End If
End Function
17. Functions to read the contents of a file using the 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
18. Function to read a row of a file using the 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) &CHR (10))
If Linenum>ubound (temparray) +1 Then
Exit function
Else
Fsolinedit = Temparray (lineNum-1)
End If
End If
End Function
19. Use the FSO to write a row of a file function
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) &CHR (10))
If Linenum>ubound (temparray) +1 Then
Exit function
Else
Temparray (lineNum-1) = Linecontent
End If
tempcnt = Join (TEMPARRAY,CHR) &CHR (10))
Set F = fso.createtextfile (Server.MapPath (filename), true)
F.write tempcnt
End If
F.close
Set F = Nothing
End Function
20. Function to add a new line of files using the 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 (&CHR) &linecontent
F.close
Set F = Nothing
End Function
Functions to modify file-specific content using the 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