Skip to main content

2 posts tagged with "file"

View All Tags

· 4 min read
Burcu Evren

File System nodes are designed to facilitate a wide array of activities within your workflow, including file and folder creation, reading from and writing to files, and checking for file existence. In this specific workflow, the focus is on verifying the existence of a specified file. If the file is found, the system proceeds to read, copy, relocate it to a different location, and finally, delete the original source file. In cases where the file is not found, the system creates the file, adds predefined text to it, copies it to a designated destination folder, and subsequently removes the source file.

How to Setup?

To begin, Login to your Robomotion workspace. If you haven't registered yet, you can create your workspace from the provided link.

What is the 'Node Name' Node?

  • Inject: This node is used to initialize the flow.
  • Function: In this node, variable, object etc. to be used in the flow are defined.
  • Create File/Dir: Used to create a file/folder.
  • Path Exists: Checks if the given Path exists. This node is of boolean type. The output of the node is true or false.
  • Switch: Used for routing the flow according to certain conditions.
  • Read File: This node is used to read a specific text file.
  • Write File: This node is used to write text into a specific text file.
  • Copy File/Dir: Copy a file/folder from the source path to the destination path.
  • Delete File/Dir: Used to delete the file/folder.
  • Stop: This node is used to stop the flow.

Flow Steps:

  1. Access to the workspace is provided through the information provided under "How to set up."
  2. The 'Inject' node is utilized to initialize the flow.
  3. Variables are defined within the 'Prepare' function node.
msg.filePath = "C:\\Robomotion\\Templates\\myText1.txt"; // The directory of the folder to be checked for files should be given
msg.destinationDir = "C:\\Robomotion\\Templates\\Copy\\"; // The directory of the destination folder to be copied must be given
msg.destinationPath = "C:\\Robomotion\\Templates\\Copy\\myText1.txt"; // The directory of the destination file to be copied must be given
msg.text = "This place should be given text."; // The text to be written in the file should be given
return msg;
  1. The 'Create Destination Dir' node generates the destination folder for the copy operation, taking the defined msg.destinationDir variable as input. Since a folder will be created, the 'Options' setting should be set to 'Directory.' Additionally, the 'Continue on Error' option should be selected, as it will trigger an error if a folder already exists.

Create File/Dir Node Options

  1. The 'Path Exists' node checks whether there are files in the defined path. This node is of boolean type, and its output is either true or false.
  2. The 'Switch' node controls the output of 'Path Exists'.

Switch Node Options

If the output is true, it indicates that the file exists. The robot reads the file using the 'Read File' node. After reading the file, the 'Copy File/Dir' node is used to copy the file from the source folder to the destination folder. Subsequently, the source file is deleted using the 'Delete File/Dir' node, and the flow comes to an end.

If the output is false, the robot creates the file using the 'Create File/Dir' node and continues its work.

  1. The text defined in the 'Prepare' function node is written to the file using the 'Write File' node.

  2. The 'Copy File/Dir' node is used for copying the file from the source folder to the destination folder.

  3. The source file is subsequently deleted using the 'Delete File/Dir' node.

File System Nodes Flow

Here you can access the complete flow by clicking on the following link:

https://casestudies.robomotion.io/designer/shared/CYBLrZXLs7nDQURQidZ9zw

· 4 min read
Burcu Evren

When an error occurs during the operation of the flow, it is managed using both the Catch node and the Try Catch structure. Errors are an inherent aspect of many processes and can vary from simple typos to intricate issues that demand hours of debugging to rectify.

An example of the error-handling structure is provided below. This example functions by verifying the existence of a specified file path. If the file does not exist within the folder directory, it is checked three times before the flow is halted. However, if the file does exist within the folder directory, it is read, and the flow is terminated

How to Setup?

To begin, Login to your Robomotion workspace. If you haven't registered yet, you can create your workspace from the provided link.

Node Overview

  • Inject: This node initializes the flow.
  • Function: In this node, variables, objects, etc., to be used in the flow are defined.
  • Path Exists: This node checks if the given path exists. It is of boolean type, and its output is either true or false.
  • Read File: This node is used to read a specific text file.
  • Catch: It is used to catch an error if one occurs during the execution of the flow.
  • Switch: This node is used for routing the flow based on specific conditions.
  • Goto: To ensure flow continuity, this node establishes connections and routing between nodes to guarantee process repetition when an error is encountered. When the flow reaches this node, it continues from wherever it was redirected.
  • Label: This node holds the redirection point for the 'Goto' node, allowing the flow to continue from its location.
  • Stop: This node is used to halt the flow.

Flow Steps

  1. Access to the workspace is granted through the instructions provided in the "How to Set Up" section.
  2. The 'Inject' node is utilized to initiate the flow.
  3. Inside the 'Prepare' function node, the variable 'msg.filePath' is defined. This variable will serve as the input for the 'Path Exists' node, and the file path to be checked for existence should be specified.
msg.filePath = "C:\\Robomotion\\Templates\\myText.txt"; // The directory of the folder to be checked for files should be given
return msg;
  1. The 'msg.try_count' variable is defined within the 'Set Try Count' function node. This variable stores the initial count of how many times the try-catch structure will be invoked when an error occurs in the flow.
msg.try_count = 0;
return msg;
  1. The 'Path Exists' node verifies whether files exist in the specified path. This node is of boolean type, and its output can be either true or false.

  2. The 'Switch' node controls the output of 'Path Exist' node.

Switch Node Options

If the output is true, it signifies that the file exists. In such cases, the robot reads the file using the 'Read File' node, and then the flow comes to a halt. This represents the error-free scenario, and the Try Catch structure remains inactive. However, if the output is false, the flow continues with the 'throw' function node.

  1. The robot triggers an error during the 'throw' function node phase because it is unable to locate the file in the designated path.
throw "The file you defined in msg.sourcePath was not found."
return msg;
  1. The 'Catch' node contains the function node that encountered an error.

  2. In the 'Plus Try Count' node, the previously defined 'msg.try_count' index is incremented by 1.

msg.try_count += 1;
return msg;
  1. The 'Switch' node examines the value of this index. If it is less than 3, the flow is rerouted to the 'Path' using the 'Go To Path' node. The 'Path Exists' node verifies whether the file exists. In the 'Go To' node, select the appropriate 'Label' node from the options section.

Goto Node Options

If the index is greater than 3, the flow is terminated. This means that the file has been checked three times and has not been found. The Try Catch structure also operates based on the value of the index.

The index value is optional and can be modified as needed.

Switch Node Options Try Catch Structure Flow

Here you can access the complete flow by clicking on the following link: https://casestudies.robomotion.io/designer/flows/HEwetqz9vGMuawiCy4efdY