How to sort files by filename: read binary files -> sort

How to sort a file list from a read binary files node

What is the error message (if any)?

When using the sort node with code some times I get the error “ERROR: Sort code doesn’t return. Please add a ‘return’ statement to your code”.
I say some times because I’m pretty sure it works some times.
The default code in the sort Node does not work with read binary files output so I changed it.
Also I can’t find the correct syntax to use the “normal” sort operation. Can’t input the correct fieldname.

Please share your workflow

Share the output returned by the last node

ERROR: Sort code doesn't return. Please add a 'return' statement to your code
NodeOperationError: Sort code doesn't return. Please add a 'return' statement to your code
    at Object.sortByCode (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Transform/Sort/utils.js:17:15)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Transform/Sort/Sort.node.js:251:45)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:698:42)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:656:68
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Information on your n8n setup

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

Hi @Duarte_Carreira :wave: Would you be able to provide an example file we could use for testing on this one for you?

Hey, I’ve just now solved the issue, kind of…

I had a workflow made on a pre-v1.0 that kept working fine after upgrading recently to 1.x. Or s I thought…

I suspect it never did run properly but I never got an error running through a webhook.

I rebuilt the workflow now, in the process I’ve put some logic in a sub-workflow. I used a code node to sort the files:

My filenames are like these:
431048PEPT0002000110252325EB_20240124_258.sgl_v2
431022PEPT0002000200064304CA_20240124_258.sgl_v2
431022PEPT0002000133441973VR_20240124_258.sgl_v2
431022PEPT0002000118073876BK_20240124_258.sgl_v2
431022PEPT0002000116983079BE_20240124_258.sgl_v2

They are plain text files.

So at this moment everything is running fine, files are downloading from an ftp server, and ingested to postgresql.

I couldn’t figure out exactly what I solved…

2 Likes

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