Example Code

Reading text file from the end

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example creates the function that will easily read defined number of lines counting from the end of text file.

 

Description

Recently someone asked if there is a function in LabVIEW that allow user to read defined number of lines counting from the end of file. Unfortunately there is not. Reading large file from the start is not a good idea so I decided to create function that will easily read lines from the end of text file.

This function reads as many lines as requested (of course not more than file has). Also I have added distinction between ANSI and Unicode files. This VI can read both without any problems.

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Specify the text file you want to read in File Path and number of rows you want to read from the end in How Many Rows?
  2. Run the VI and it will read the defined lines from the end of the file and show them in the Selected Rows.

 

 

Additional Information or References  

VI Snippet

1.png

 

The Poem.txt in the ZIP file just a testing file for the example, you can specify an text file you want to read.

If you have any suggestions please ask.

Enjoy!

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 



Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
davyx8
Member
Member
on

Thanks alot, that saved me some time!