Can't read file if filename contains brackets

Describe the problem/error/question

I’m trying to read a file but it gives an empty result if the filename contains both type of brackets. It will give a result if I remove the brackets from the filename

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:**1.81.4
  • **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

most likely the spaces are your problems and not the brackets.
I’m unsure how Windows works (avoiding it since windows 3.1) but with Linux you would put the filename in " " to get around the problems with spaces.

Ok I have some windows I could spin up for testing … yes this seems to work.

so try this …

I tried it again with double quotes and it still doesn’t give an output

sorry, don’t have a windows where I could spin up n8n to see why it might not work.
I assume you have checked that n8n does have permission to access those folders and can see the files in there?

Yes n8n has permission to access folder/files I have tested by renaming the file. It just doesn’t like the brackets/space

you could also try escaping it with \

test\ file\[asdf\].mkv

but again, not sure how windows expects this to be escaped and how npm behaves in windows.

Escaping the brackets work. How do I auto escape all type of brackets ( ) { } [ } instead of manually inserting cause I’m watching a folder for new files

I would use an inline expression something like:

{{$json.path.replace('[', '\[').replace(']', '\]').replace('{', '\{').replace('}', '\}')}}
etc

It seems to only replace one set of brackets and it’s not reoccurring since the filename may contain multiple brackets. After testing I realized the path to file needs to use forward-slash instead of back-slash since n8n requires it even on windows which I don’t know how to do this

Oh yes my mistake it is .replaceAll(). You can replace spaces and backslashes as well.

I believe you need to escape backslashes as well so you do them double.

{{$json.path.replace('[', '\\[').replaceAll(']', '\\]').replaceAll('{', '\\{').replaceAll('}', '\\}')}} etc (add other replacements by appending another .replaceAll(‘’, ‘’))

1 Like