Read from text file line number

From NSIS Wiki
Jump to navigationJump to search
Author: Afrow UK (talk, contrib)


Description

This is a simple script that outputs whatever text is on the inputted line number.

Usage

Push 23 ;line number to read from
Push "$INSTDIR\file.txt" ;text file to read
 Call ReadFileLine
Pop $0 ;output string (read from file.txt)

The Script

Function ReadFileLine
Exch $0 ;file
Exch
Exch $1 ;line number
Push $2
Push $3
 
  FileOpen $2 $0 r
 StrCpy $3 0
 
Loop:
 IntOp $3 $3 + 1
  ClearErrors
  FileRead $2 $0
  IfErrors +2
 StrCmp $3 $1 0 loop
  FileClose $2
 
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd

-Stu (Afrow UK)