Can not read path in execute command Node

Describe the problem/error/question

I’m trying to use the Execute Command node to create a list of files in a directory but it can’t read the path if I use an expression in the pathway

What is the error message (if any)?

Command failed: dir “C:\Users\Administrator\Desktop\Manga\Batch{{ $json.dirs.replace(/\r?\n|\r/g, “”) }}” /b /o:gn The system cannot find the path specified. [item 0]

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:1.89.2
  • **Database (default: SQLite):default
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • **Operating system:Windows Server 2022

Hello @RurLko.
I hope you are well!

Use a Set node before passing the expression to the Execute Command to evaluate how the path is being generated. For example:

Add the Set node and set a field like:
Field name: finalPath

=`C:\Users\Administrator\Desktop\Manga\Batch\${$json.dirs.replace(/\r?\n|\r/g, "")}` 

Update the command in the Execute Command node to make sure it concatenates the path correctly…

=dir "C:\Users\Administrator\Desktop\Manga\Batch\{{$json.dirs.replace(/\r?\n|\r/g, "").trim()}}" /b /o:gn

Below is a suggestion of your workflow with some suggestions for improvements. See if this makes sense to you.

I hope I helped.
Big hug

I used the Set node to see how’s it’s generating the path and it seems that it’s showing up as an expression instead of the data. How to fix it?

This workflow suggestion that I sent should be tested separately from your workflow, so that you can check if the suggestion makes sense and so that you can test it according to your needs.

Open a separate workflow and test the suggestions below.

You are setting the dirs field with a string that contains the expression {{$json.dirs.replace(…)}}, but as raw text, and not as an expression to be executed.

Go to the SET NODE in the Manual Mapping tab and locate the fields to set configuration for the dirs value, then replace the current content in the Value field with

=`C:\Users\Administrator\Desktop\Manga\Batch\${$json.stdout.replace(/\r?\n|\r/g, "").trim()}`

See if it will display the generated paths as…
C:\Users\Administrator\Desktop\Manga\Batch\subdir1
C:\Users\Administrator\Desktop\Manga\Batch\subdir2
C:\Users\Administrator\Desktop\Manga\Batch\subdir3

1 Like

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