The READ_TEXTFILE function reads all the lines of a text file as a string array.

Tip: READ_TEXTFILE is designed for flat text files of unstructured text. If your text file has columns of data, you might instead use READ_ASCII or READ_CSV.

This routine is written in the IDL language. Its source code can be found in the file read_textfile.pro in the lib subdirectory of the IDL distribution.

Examples


The following reads the data in a text file, ascii.txt, within the IDL distribution:

IDL> file = FILEPATH('ascii.txt', SUBDIR=['examples', 'data'])
IDL> data = READ_TEXTFILE(file)
IDL> help, data
  DATA            STRING    = Array[20]
IDL> data
This file contains ASCII format weather data in a comma delimited table
with comments prefaced by the "%" character. The columns represent:
Longitude, latitude, elevation (in feet), temperature (in degrees F),
dew point (in degrees  F), wind speed (knots), wind direction (degrees)
-156.9500, 20.7833, 399, 68, 64, 10, 60
-116.9667, 33.9333, 692, 77, 50, 8, 270
...

Syntax


Result = READ_TEXTFILE (Filename )

Return Value


The result is a string array containing the lines within the text file. If Filename is empty then a scalar null string is returned.

Arguments


Filename

A scalar string containing the name of the file to read.

Keywords


None

Version History


9.3

Introduced

See Also


READ_ASCII, READ_BINARY