devxlogo

Display a Partial Text File Using FSO

Display a Partial Text File Using FSO

This script reads specific lines of text from any text file and then stores the lines in an array that you can assign to a variable for data display.

<%Const ForReading = 1' The following line numbers will be read into the arrayDim myArr(4)myArr(0)="10"myArr(1)="12"myArr(2)="15"myArr(3)="17"' Counter used for array incrementi = 0' Create FSO Object & Set File to ReadSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.GetFile("C:inetpubwwwrootReadme.Txt")' Open file for reading.Set objTextFile = objFile.OpenAsTextStream(ForReading)' Loop Through TEXT File and Get Text to DisplayDo While objTextFile.AtEndOfStream <> True    CurrLine = objTextFile.Line    If Cstr(CurrLine) = Cstr(myArr(i)) Then	myArr(i)=UCASE(objTextFile.ReadLine)        i = i + 1    Else        CurrLine = objTextFile.ReadLine    End IfLoop' Set variablesLine10 = myArr(0)Line12 = myArr(1)Line15 = myArr(2)Line17 = myArr(3)' Close & DestroyobjTextFile.CloseSet objFSO = NothingSet objFile = Nothing' Display DataResponse.Write "Line 10 reads: " & Line10Response.Write "Line 12 reads: " & Line12Response.Write "Line 15 reads: " & Line15Response.Write "Line 17 reads: " & Line17%>
See also  Essential Measures for Safeguarding Your Digital Data
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist