Print Page | Close Window

Read Multiple Lines From A Text File

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=10823
Printed Date: 31 March 2026 at 5:14am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Read Multiple Lines From A Text File
Posted By: neotrix
Subject: Read Multiple Lines From A Text File
Date Posted: 10 June 2004 at 11:05pm
Originally posted by dpyers dpyers wrote:

You never go to the next line... Move

theTextLine=theTextFile.ReadLine
theFields=Split(theTextLine, VBTab)

After

While Not theTextFile.AtEndOfStream

Hello, well can anyone please explain this a little further, like how to read multiple lines from a text file, i really dont understand anything from the code and i need it very badly...

what i want to do is my text file'z contents will be

Originally posted by MyTextFile.txt MyTextFile.txt wrote:

MovieTitle
SongName1
SongName2
SongName3

i basically want to read 22 lines from a text file, (It is known, and the format of the text file is fixed) i want to store each line in different variables like strVariable1 strVariable2 strVariable3 etc etc... dont know if i can explain my self or not.. but what shud i do ?? I dont think it will be difficult ?



-------------
http://www.muhammadbinyusrat.com/blog/" rel="nofollow - Say to the believing men..



Replies:
Posted By: dpyers
Date Posted: 11 June 2004 at 12:56am

Not Tested

<%
'Create your own instance of a File System Object
Set myFSO = Server.CreateObject("Scripting.FileSystemObject")

'Use your FSO to "read" the entire file into a work area
Set strEntireTextFile = myFSO.OpenTextFile("C:\mydirectory\myfile.txt")

'Initialize a line counter
strLineCount = 0

'Do the following loop until the end of data
While Not strEntireTextFile.AtEndOfStream

'Read one line and increment the count of lines read
strSingleTextLine=theTextFile.ReadLine
strLineCount = strLineCount + 1

If strLineCount < 23 then

 'Do stuff depending upon which line you're on
 Select Case strLineCount
  Case 1
   strline1 = strSingleTextLine
  Case 2
   strline2 = strSingleTextLine
  Case 3
   strline3 = strSingleTextLine
   .
   .
   .
  Case 22
   strline22 = strSingleTextLine
 End Select

End If

' Go bact to the beginning of the loop
Wend

'Free the resources used
strEntireTextFile.Close
Set strEntireTextFile = Nothing
%>



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: neotrix
Date Posted: 11 June 2004 at 1:24am

Thankyou so very very Much... Xactly What i Needed

Another small Question......

Can u tell me how can i store the names of files found a perticular folder inside an array ?

Thanks



-------------
http://www.muhammadbinyusrat.com/blog/" rel="nofollow - Say to the believing men..


Posted By: neotrix
Date Posted: 11 June 2004 at 1:43am

You Posted This Code Somewhere... (i've modified it a liiiiiiiiiiiitttle bit)

Originally posted by dpyers dpyers wrote:


Set oFSO = CreateObject("Scripting.FileSystemObject")

CurrentPath = Server.MapPath("data")
Set oFolder = oFSO.GetFolder(CurrentPath)
Set oFolderContents = oFolder.Files

dim i
i = 0
For Each File in oFolder.Files
     Response.Write file.Name  & "<br />"
next

Set oFolder = Nothing
Set oFolderContents = Nothing
Set oFSO = Nothing

It dose work very well.. but the problem i see in this, is that it also writes the file extension (.txt) i want it to write the file name.. and skip the extension, is it possible



-------------
http://www.muhammadbinyusrat.com/blog/" rel="nofollow - Say to the believing men..


Posted By: Mart
Date Posted: 11 June 2004 at 2:57am
Left(File.Name, InStrRev(File.Name, ".") - 1) Should work



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net