Skip to main content

How to Read a Notepad File Line by Line

· 2 min read
Selin Gizem Özkan

Reading a notepad file line by line is a common task in programming and data processing. By breaking down the contents of a file into individual lines, you can analyze or extract specific information more efficiently.

In this blog, we will explore the steps to read a notepad file line by line using a code example.

Whether you're a beginner or an experienced programmer, mastering this skill will enhance your ability to work with text-based files and empower you to extract valuable insights from large datasets. Let's dive in and learn how to read a notepad file line by line.

How to Setup?

To begin, Log in to your Robomotion workspace. If you haven't registered yet, you can create your workspace from the provided link. Once you have access to your workspace, you can proceed by using the Read File node from the File System package to read the provided input.

About File System Package

The File System package consists of 11 node options that allow you to manage your files easily within your workflow.

Read File nodes

What is Read File node?

The "Read File" node is responsible for reading the contents of a file and making them available for further processing. It abstracts the file reading process, simplifying the task of reading files and integrating them into a larger workflow or system.

Flow Steps

  1. Inject node is used to initialize the flow.
  2. In the Read File node, the path of the file to be read is provided as input.

Read File node options

  1. Write the regex code used to read the menu line by line within the Function node. This code splits the given text into lines and returns them as a list. It uses the regular expression \r?\n to match the line breaks.

Function Node Named “Split Line”:

Code-Block:

msg.lines = msg.text.split(/\r?\n/); return msg;

  1. The elements of the list are iterated one by one with the "For Each" node.
  2. They are printed using the "Debug" node.
  3. Loop through the list using 'Go to' and 'Label' nodes. Connect the "Go to" node to the "Label" node to create a loop.
  4. When the elements in the list are finished, the flow exits the loop and goes to the "Stop" node.

Read File Flow