Code: Select all
FileReadLine, line, "file.txt", 3
Code: Select all
FileReadLine, line, "file.txt", 3
Code: Select all
Line := StrSplit(FileRead('thefile.txt'), '`n', '`r')
Code: Select all
MsgBox(FileReadLine(FileSelect(),InputBox()))
FileReadLine(Filename, LineNum)
{
local File := FileOpen(Filename, "r-wd")
if (LineNum < 0)
{
local Pos := File.Pos
local Lines := 0
while (!File.AtEOF)
++Lines, File.ReadLine()
LineNum := Lines - Abs(LineNum) + 1
File.Seek(Pos)
}
while (!File.AtEOF)
{
if (A_Index == LineNum)
return File.ReadLine()
File.ReadLine()
}
throw
}
Code: Select all
;AHK v1
q:: ;create large text file
vLen := 18
vLine := SubStr("abcdefghijklmnopqrstuvwxyz", 1, vLen)
VarSetCapacity(vOutput, 20000000*2)
Loop % 10000000/(vLen+2)
vOutput .= vLine "`r`n"
vPath := A_Desktop "\z test 10MB text.txt"
if !FileExist(vPath)
FileAppend, % vOutput, % "*" vPath, UTF-8
return
w:: ;read line from large text file
vPath := A_Desktop "\z test 10MB text.txt"
vNum := 100
vTickCount1 := A_TickCount
Loop % vNum
FileReadLine, vText, % vPath, 3
vTickCount2 := A_TickCount
MsgBox, % vText
Clipboard .= "`r`n" (vTickCount2-vTickCount1)
vTickCount1 := A_TickCount
Loop % vNum
{
FileRead, vText, % vPath
vText2 := StrSplit(vText, "`n", "`r")[3]
}
vTickCount2 := A_TickCount
MsgBox, % vText2
Clipboard .= "`r`n" (vTickCount2-vTickCount1)
return
;some results (msec):
;FileReadLine FileRead/StrSplit
;16 11232
;16 11185
;0 11123
Users browsing this forum: zed6250jb and 26 guests