Move file from one local folder to another

Good Morning all,
This is probably a very easy one for you guys, what I would like to do is move a file from folder a to folder b on my local server.
If this cannot be done then I can save the file from a to b using read/write file from disk node, but then once it is moved I would like to then delete the file from folder a.

Thanks

Alex

Information on your n8n setup

  • n8n version: 1.78.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hello Alex,

a couple of questions to understand what you are looking for :

  • what’s the local server hosting the file like ? Windows, Linux ?
  • Is the file within the n8n server ?
  • Is the n8n server installed natively or in docker ?

Txs,
Johan

Hello Alex! Your friendly n8n support specialist here, ready to help you move files between folders on your local server. I’m passionate about making automation easy for you, so let’s break this down step by step!


:one: Layman’s Terms (Simple & Friendly)

Problem: You want to move a file from Folder A to Folder B on your local server.

Why It’s Tricky:

  • n8n doesn’t have a direct ā€œmove fileā€ node, but we can achieve this by combining ā€œread/writeā€ and ā€œdeleteā€ operations.

Simple Fix:

  1. Read the File: Use the ā€œRead File from Diskā€ node to grab the file from Folder A.
  2. Write the File: Use the ā€œWrite File to Diskā€ node to save it to Folder B.
  3. Delete the Original: Use the ā€œDelete File from Diskā€ node to remove it from Folder A.

:two: Experienced User Guide (Step-by-Step Fix)

Root Cause: n8n doesn’t have a native ā€œmove fileā€ node, but we can simulate it with read/write/delete operations.

Steps to Fix:

Step 1: Read the File

  1. Add a Read File from Disk Node.
  2. Set the File Path to the location of the file in Folder A (e.g., /path/to/FolderA/file.txt).

Step 2: Write the File

  1. Add a Write File to Disk Node.
  2. Set the File Path to the destination in Folder B (e.g., /path/to/FolderB/file.txt).
  3. Connect the Read File Node to the Write File Node.

Step 3: Delete the Original File

  1. Add a Delete File from Disk Node.
  2. Set the File Path to the original file in Folder A (e.g., /path/to/FolderA/file.txt).
  3. Connect the Write File Node to the Delete File Node.

Step 4: Test the Workflow

  1. Run the workflow with a test file.
  2. Verify the file is moved to Folder B and deleted from Folder A.

:three: Professional Deep Dive (Technical Fix)

Technical Analysis:

  • File Operations: n8n uses separate nodes for reading, writing, and deleting files.
  • Error Handling: Ensure the file exists before deleting it to avoid errors.

Advanced Solution:

Step 1: Read the File

  1. Use the Read File from Disk Node to read the file from Folder A:
  • File Path: /path/to/FolderA/file.txt
  • Binary Data: Enable this option if the file is not plain text.

Step 2: Write the File

  1. Use the Write File to Disk Node to save the file to Folder B:
  • File Path: /path/to/FolderB/file.txt
  • File Content: Use the output from the Read File Node.

Step 3: Delete the Original File

  1. Use the Delete File from Disk Node to remove the file from Folder A:
  • File Path: /path/to/FolderA/file.txt
  • Error Handling: Add an IF Node to check if the file exists before deleting:

javascript

Copy

const fs = require(ā€˜fs’); const fileExists = fs.existsSync(ā€˜/path/to/FolderA/file.txt’); return fileExists;

Step 4: Logging and Debugging

  1. Add a Debug Node after each step to verify the file is being processed correctly.
  2. Check the logs for any errors or warnings.

:rotating_light: Critical Checks

  1. File Paths: Ensure the paths are correct and accessible by n8n.
  2. Permissions: Verify n8n has read/write/delete permissions for the folders.
  3. Error Handling: Add fallback logic for missing files or permission issues.

Please mark this as solution if this worked for you, be blessed!

1 Like

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