AHK-v2-script-converter icon indicating copy to clipboard operation
AHK-v2-script-converter copied to clipboard

FileReadLine

Open mmikeww opened this issue 7 years ago • 3 comments

can replace

FileReadLine, line, C:\My Documents\ContactList.txt, 5

with

Loop, Read, C:\My Documents\ContactList.txt
{
   if (A_Index = 5)
   {
      line := A_LoopReadLine
      break
   }
}

or using file objects

file := FileOpen("C:\My Documents\ContactList.txt", "r")
Loop 5
   line := file.ReadLine()
file.Close()

mmikeww avatar Dec 18 '16 04:12 mmikeww

what about this from the v1 help file?

Loop
{
    FileReadLine, line, C:\My Documents\ContactList.txt, %A_Index%
    if ErrorLevel
        break
    MsgBox, 4, , Line #%A_Index% is "%line%".  Continue?
    IfMsgBox, No
        return
}

that would mean something like this

Loop
{
    i := A_Index
    Loop, Read, C:\My Documents\ContactList.txt
    {
       if (A_Index = i)
       {
          line := A_LoopReadLine
          break
       }
    }
    if ErrorLevel
        break
    MsgBox, 4, , Line #%A_Index% is "%line%".  Continue?
    IfMsgBox, No
        return
}

but this code is also checking ErrorLevel, really not any good solution

mmikeww avatar Dec 18 '16 04:12 mmikeww

This is the correct conversion (not yet implemented) if ErrorLevel is not present in the script, we can skip the setting of it.

try{ ErrorLevel := 0 Text_FileRead := FileRead("C:\Users\Dimitri\Documents\FTsPLog.txt") line := StrSplit(Text_FileRead,"n","r")[A_Index] } Catch{ line := "" ErrorLevel := 1 }

dmtr99 avatar Sep 26 '21 20:09 dmtr99