Moving file only after it is processed

  1. I have source folder and destination folder.
  2. I have a file in the source folder.
  3. I am using "file in" to read the file and generating a message for line.
  4. For moving the file from source folder to destination folder, I know I can use the "fs-ops-move" node.

Question: How can I wait until the last record (don't know how many records in the file before hand, nor I would like to know) is delivered as a message by the "file in" node and then move this file from source folder to destination folder?

Figured out. The "file in" node adds "complete" property and sets its value to "true" when the file processing is complete.

  1. Connected "csv" node to "file in" node. The csv node emits one json message per line.
  2. Connected "function" node to "csv" node. In this node, wrote following code:
if (msg.complete == null || msg.complete == false) {
    return null; //stops the execution of following nodes
}
else {
    node.warn("Message parts count is " + msg.parts.count);
    node.warn("File finished processing: " + msg.topic);
    //Added the path module to the Setup tab.
    //Set the msg.topic to file path earlier
    msg.file = path.parse(msg.topic).base; 
    return msg;
}
  1. Connected "fs-ops-move" node to the "function" node. Set the source and destination folders. Set the source file name and destination file name to msg.file

It all worked!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.