Hi everyone,
I’m trying to save multiple local files in n8n using a loop.
My workflow works fine overall — a Code node generates several items, each with an id or fileBase field (for example: clip_001, clip_002, etc.).
Then I use a Split In Batches node with Batch Size = 1 to process each item one by one, and a Write File node to save them under /files/.
The issue is that every time a file gets written, the previous one is overwritten — instead of producing separate files (like clip_001.txt, clip_002.txt, etc.), I only end up with one file.
I’ve tried different expressions for the file name, like:
/files/{{ $json.fileBase }}.txt
/files/test_{{ $itemIndex + 1 }}.txt
/files/test_{{ $json.id + 1 }}.txt
but none of them seem to create unique outputs — the result is always a single file being updated.
So my questions are:
-
How can I correctly pass a unique value (for example,
item + 1orDate.now()) to generate unique file names for each loop iteration? -
And what’s the proper setup for the Write File node when saving simple text (not binary)?
Any guidance or example JSON would be greatly appreciated.
Thanks a lot!
