All templates
Text ManipulationIntermediate
Count Lines of a Text File
Robomotion•Updated 6 months ago

Overview
Opens a text file and reports the number of lines it contains. A tiny helper you can drop into larger analytics flows.
Count Lines of a Text File
Apart from reading text from documents, many tasks require users to inspect various characteristics of the retrieved data. Therefore, Robomotion provides properties that describe each variable's content, such as the number of lines a text file has.
What Count Lines of a Text File can do
- Build default path (
Core.Programming.Function) — setsmsg.fixture_pathto the bundledsample.txtunder$Home$/templates/.../fixtures. - Intro Dialog (
Core.Dialog.MessageBox,info) titledDescriptionexplaining that the flow prompts for a text file and reports its line count. - Input Dialog (
Core.Dialog.InputBox) titledPlease select a text file..., defaultmsg.fixture_path→msg.selected_text_file. - Branch (
Core.Programming.Function,outputs: 2) — continue when the path is non-empty and ends in.txt; otherwise skip straight to the completion dialog. - Read file (
Core.FileSystem.ReadFile,optBase64: false) frommsg.selected_text_file→msg.file_contents. - Count lines (
Core.Programming.Function) — splitsmsg.file_contentson\n, drops a trailing empty element, storesmsg.line_countand buildsmsg.dialog_text=The file has N lines!. - Results Dialog (
Core.Dialog.MessageBox,info) titledResults...showingmsg.dialog_text, then a finalExample completed!dialog beforeCore.Flow.Stop.
Behind the scenes
Core.FileSystem.ReadFilereturns the whole file as a string, so the Function node does the line splitting itself and trims a trailing blank line so files that end with a newline don't over-count.- The completion dialog runs on both branches (valid read and skipped selection) so the user always gets a clear end-of-flow acknowledgement.