AutoHotKey를 사용하는 사람들
오늘: 467
어제: 624
전체: 200,883
회원: 1,883
접속: 25 (회원 0)

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). This 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 on (the default). For 예제: 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).

관련 명령어

FileRead, FileAppend, File-reading loop, IniRead

예제

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

 

Copyright Tleap. All rights reserved.