with n8n old version, used to fetch all files under path with command, e.g. /Users/123/" -maxdepth 2 -mindepth 2 -type f , (2 lvls down the path); but with v2.x, command node no longer available, wondering any similar node to do the same. thanks.
Hey @snxnj, while you wait for a response, here are some things that might help:
Suggested resources
Automatically matched to your question.
Docs:
Forum:
@Wouter_Nigrini, @A_A4, @zenithflare - you’ve helped with similar issues before, can you take a look?
Automatically suggested by n8n’s community bot. It’s a pilot - please share feedback here.
Hi @snxnj
The node is still a core part of n8n, but if you are using a self-hosted version, it might be disabled via an environment variable.
- The Issue: For security, n8n can be configured to exclude certain nodes.
- The Fix: Check your environment variables for
NODES_EXCLUDE. IfExecute Commandis in that list, you must remove it to use the node. You can set it to an empty list to enable all nodes:NODES_EXCLUDE="[]"
If you cannot use the “Execute Command” node due to security restrictions, the standard way to perform file system operations in newer versions of n8n is using the Code Node with Node.js.
Does that answer your question?
@snxnj Hi! You can try this! If you just want files, you don’t need any command nodes, the Read/Write files from disk can take glob for file selection, you can do /Users/123/*/* Each asterik, I think it’s called an asterik? goes down a file level. It reads the files as items!
system showing: Access to the file is not allowed. Allowed paths: /Users/123/.n8n-files, looks like 2.x version running in sandbox.
Well i gave you an example folder, so change it to a legitimate directory, and here’s your fix, use this env var
N8N_RESTRICT_FILE_ACCESS_TO=/Users/123
Like let’s say your name was John, your folder would be /Users/John/folder, ect (or whatever your filesystem format uses
will try. how about mv command, like mv file A to path B; without command node, how to make it happen. thanks
if you wanted to use commands it’ll give you more power since the node above is for read/write, the best bet is the command node, I know you don’t really want to use it, but it’s the best bet
(read anshuls post below for the fs guide)
check for @kjooleng idea, the NODES_EXCLUDE if command node is under that list, remove it
(the node wont show because its a self-hosted node
Hi @snxnj
fs does work in the Code node, it just has to be allowed first. Set this and restart:
NODE_FUNCTION_ALLOW_BUILTIN=fs
Then the move is one line:
const fs = require('fs');
fs.renameSync('/Users/123/source/file.txt', '/Users/123/destination/file.txt');
return $input.all();
renameSync only works inside one filesystem, so if the source and destination sit on different mounts use fs.copyFileSync followed by fs.unlinkSync instead. If your instance runs task runners in external mode, that variable belongs in /etc/n8n-task-runners.json as an env-override rather than on the container.