Dear,
I get this result when i choose path /
but when i choose /data path:
Where is the problem?
Goal of my python script: get all filespath into a list and process each file
Please share your workflow
"nodes": [
{
"parameters": {
"language": "python",
"pythonCode": "# Loop over input items and add a new field called 'myNewField' to the JSON of each one\nimport os\nimport json\ndata = {}\nindex=0\n#data['key'] = 'value'\nresult_path=[\"test1\",\"test2\"]\ndef list_files_recursive(path='',index=index):\n \n for entry in os.listdir(path):\n full_path = os.path.join(path, entry)\n if os.path.isdir(full_path):\n list_files_recursive(full_path,index)\n else:\n print(full_path)\n data[str(index)] = ''+full_path\n index+=1\n #result_path.append(full_path)\n\n# Specify the directory path you want to start from\ndirectory_path = r'/'\nlist_files_recursive(directory_path,index)\nprint(len(result_path))\nprint(result_path[0])\njson_string = json.dumps(result_path)\nprint(json_string)\nfor item in _input.all():\n item.json.myNewField = 1\n#return _input.all()\njson_data = json.dumps(data)\nprint(json_data)\nreturn [{\"pathFiles\":json_data}]\n#return [{\"pathFiles\":{\"0\":\"/\",\"1\":\"/data\"}}]"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-180,
-340
],
"id": "328ced5c-d5be-4967-9a5f-b79d412942dd",
"name": "Code",
"alwaysOutputData": true
}
],
"connections": {},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "54c34153644f41955df1b045b27e23c5aa493246a7d7e5e8ad537b7abbcf8133"
}
}
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system: