FSO Use method and example explanation

Source: Internet
Author: User
Tags chr

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) &AMP;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) &AMP;CHR (10))
If Linenum>ubound (temparray) +1 Then
Exit function
Else
Temparray (lineNum-1) = Linecontent
End If
tempcnt = Join (TEMPARRAY,CHR) &AMP;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 (&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.