amount of lines in a text file

Results 1 to 2 of 2

Thread: amount of lines in a text file

  1. #1
    Join Date
    Dec 1969

    Default amount of lines in a text file

    Is there a way to find out the amount of lines in a text file?

  2. #2
    Join Date
    Dec 1969

    Default RE: amount of lines in a text file

    let&#039s assume you have a file named "MyFile.txt" in the same folder as your asp file. Use this code:<BR>&#060;%<BR>&#039get the absolute path<BR>strTextFile = Server.MapPath("MyFile.txt")<BR><BR>&#039create an instance of a FileSystemObject object<BR>Set objFSO = Server.CreateObject("Scripting.FileSystemObject")< BR><BR>&#039open the text file as a text stream object<BR>&#039 1 = ForReading<BR>Set objTStream = objFSO.OpenTextFile(strTextFile, 1)<BR><BR>&#039move cursor to the last line<BR>Do While Not objTStream.AtEndOfStream<BR> objTStream.SkipLine<BR>Loop<BR><BR>&#039read number line<BR>intLineNum = objTStream.Line<BR><BR>&#039write output<BR>response.Write "There are " & intLineNum & " lines in this file."<BR><BR>&#039close object<BR>objTStream.Close<BR>%&#062;<BR><BR>There might be a way to by-pass the loop I have above and go directly to the last line. If you figure it out, please let me know:<BR><BR>Happy programming!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts