Forum Discussion

cklein_1's avatar
cklein_1
Occasional Contributor
14 years ago

Reading a txt file

Is there a way to read a specific line in a txt file? The .ReadLine() reads all lines.



Thanks,

Chris

3 Replies


  • Hi,





    Set the cursor position to the beginning of the needed line and use the aqTextFile.ReadLine or VBScript native ReadLine method:







    LineNumber = 7

    Set myFile = aqFile.OpenTextFile("C:\1.txt", aqFile.faRead, aqFile.ctANSI)

    myFile.SkipLine(LineNumber - 1)

    Log.Message(myFile.ReadLine)

  • cklein_1's avatar
    cklein_1
    Occasional Contributor
    Thanks!



    Can I do a Check Point on that? If the text didnt match a certain string then fail the test? I'm working in jscript.



    Thanks again,

    Chris



  • Hi,





    You can post an error in this case - this will stop your test (note that the "Stop on error" option of your project properties must be enabled):







    LineNumber = 7;

    myFile = aqFile.OpenTextFile("C:\\1.txt", aqFile.faRead, aqFile.ctANSI);

    myFile.SkipLine(LineNumber - 1);

    if (myFile.ReadLine() != "stringToCompare")

      Log.Error("The strings are not equal");