Scan From File
- Updated2025-03-14
- 4 minute(s) read
Scan From File
Scans text in a file for string, numeric, path, and Boolean data, converts the text to a data type, and returns a duplicated refnum and the converted outputs in the order scanned. This function does not work for files inside an LLB.
You can use this function to read all the text in the file. However, you cannot use this function to determine a starting point for the scan. To do so, use the Read from Text File function and the Scan From String function.

Inputs/Outputs
![]() format string specifies how to convert the input string into the output arguments. The default is to scan the string according to default behavior for the data types of the outputs wired. Right-click the function and select Edit Scan String from the shortcut menu to create and edit the format string. This input accepts a maximum of 255 characters. ![]() input file can be a refnum or absolute file path. If it is a refnum, this node opens the file specified by the refnum. This function creates the specified file if it does not already exist. The default is to display a file dialog box and prompt you to select a file. If you specify an empty or relative path, this function returns an error. ![]() error in describes error conditions that occur before this node runs. This input provides standard error in functionality. ![]() ![]() output file refnum is the refnum of the file that the VI read. You can wire this output to another file function, depending on what you want to do with the file. The default is to close the file if it is referenced by a file path or selected from the file dialog box. If input file is a refnum, LabVIEW assumes that the file is still in use until you close it.![]() error out contains error information. This output provides standard error out functionality. ![]() |
Increase the number of parameters by right-clicking the function and selecting Add Parameter from the shortcut menu or by resizing the function.
If you wire a block diagram constant string to format string, LabVIEW uses format string to determine the number of outputs and the data type of each output at compile time. If the types you wire to the outputs do not match the types determined by format string, you must change the output types before the VI can run.
If you do not directly wire a block diagram constant to format string, LabVIEW checks for type mismatches at run time. If you want to scan values that have data types other than double-precision, floating point, you must wire the data types to default 1..n.
When you use the match characters not in set format specifier (%[^...]), which is used frequently to read an entire string, the matched character(s) are left in the file stream. %[^\n\r] matches an entire line of text, but the carriage return and new line are left behind. To remove these characters, use %[^\n\r]\n\r.
Examples of Formatting Strings
input string | format string | default(s) | output(s) | remaining string |
---|---|---|---|---|
abc, xyz >12.3+56i 7200 | %3s, %s%f%2d | — | abc | 00 |
— | xyz | |||
0+00i | 12.3+56i | |||
— | 72 | |||
Q+1.27E–3 tail | Q%f t | — | 1.27E–3 | ail |
0123456789 | %3d%3d | — | 12 | 6789 |
345 | ||||
X:9.860 Z:3.450 | X:%fY:%f | 100 (I32) | 10 | Z: 3450 |
100.00 (DBL) | 100.00 | |||
set49.4.2 | set%d | — | 49 | .4.2 |
color: red | color: %s | blue (enum {red, green, blue}) | red | — |
abcd012xyz3 | %[a-z]%d %[a-z]%d | — | abcd | — |
12 | ||||
xyz | ||||
3 | ||||
welcome to LabVIEW, John Smith | %[^,],%s | — | welcome to LabVIEW | Smith |
John |
Examples
Refer to the following example files included with LabVIEW.
- labview\examples\File IO\Text (ASCII)\Format Into File and Scan From File.vi