FileReadLine

Reads the specified line from a file and stores the text in a variable.

FileReadLine, OutputVar, Filename, LineNum

 

Parameters

OutputVar The name of the variable in which to store the retrieved text.
Filename The name of the file to access, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. Windows and Unix formats are supported; that is, the file's lines may end in either carriage return and linefeed (`r`n) or just linefeed (`n).
LineNum Which line to read (1 is the first, 2 the second, and so on). In v1.0.30.03+, this parameter can be an expression.

 

ErrorLevel

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

 

Remarks

Generally, this command should be used only for small files, or in cases where only a single line of text is needed. To scan and process a large number of lines (one by one), use a file-reading loop for best performance. To read an entire file into a variable, use FileRead.

Although any leading and trailing tabs and spaces present in the line will be written to OutputVar, the linefeed character (`n) at the end of the line will not. Tabs and spaces can be trimmed from both ends of any variable by assigning it to itself while AutoTrim is off (the default). For example: MyLine = %MyLine%

Lines up to 65,534 characters long can be read. If the length of a line exceeds this, the remaining characters cannot be retrieved by this command (use FileRead or a file-reading loop instead).

 

Related

FileRead, FileAppend, file-read loop, IniRead

 

Example

i = 0
Loop
{
	i += 1
	FileReadLine, line, C:\My Documents\ContactList.txt, %i%
	if ErrorLevel <> 0
		break
	MsgBox, 4, , Line #%i% is "%line%".  Continue?
	IfMsgBox, No
		return
}
MsgBox, The end of the file has been reached or there was a problem.
return