How can I move files in the file system?

I have mapped an SMB share and there files end up in an inbox, these should be moved after processing. There is a node for Dropbox and Co. How can I implement this in the SMB share?

At the moment I am not reading the file name completely. But just run through all * .csv files. How do I get the file name of the file?

How can I move all files into an error folder that do not conform to the * .csv convention?

thx* John

The name of the file is in the property “fileName” in the binary data:
Screenshot from 2021-03-16 08-50-01

There is currently no node to move files on the file system. You would have to do it with the “Execute Command” node instead and use the mv command.

const newItems = [];

for(let i=0; i<items.length; i++) {
items[i].json.file = String(items[i].json.fileName);
newItems.push({json: items[i].json});
}
return newItems;

I collect all data from the CSV files with the merge node. So that I can move the documents in the line processing, I need the filename.

Sorry, do not understand. I did not say that you do not need the file name. I simply told you where you can find it.

The fileName works! But creating folders does not work yet with the cmd-node.

CMD:
mkdir --parents /media/path1/{{$json["jobid"]}}/; mv "/media/path2/PDF_{{$json["jobid"]}}.pdf" $_

mkdir: can’t create directory ‘/media/path1/’: Permission denied BusyBox v1.31.1 () multi-call binary. Usage: mv [-fin] SOURCE DEST or: mv [-fin] SOURCE… DIRECTORY Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY -f Don’t prompt before overwriting -i Interactive, prompt before overwrite -n Don’t overwrite an existing file

Sounds like n8n does not have the access rights to write to the /media folder. If you change that it should work. The mv complains because it is not complete. You have to define a source and a destionation.

I mapped the folder on the host system and it has access on the host system (Ubuntu) and I can also see the content of the mapped folder.

sudo mount -t cifs -o username=<username>,password=<pass>,dir_mode=0777,file_mode=0777,nounix //192.168.0.2/Path1/ /home/administrator/n8n-files/Path1

Now when I log into the Docker machine. I see the Path1 folder but no content is displayed.

@Jan: Do you have any ideas how I can make the content of the mouted folder available in n8n?

Do you mount the folder also correctly in Docker with -v?

No that was the problem! I have mounted the drive on the host machine and have mapped the folder in which I have mounted with the Docker container :scream: !

mount on the host system:
sudo mount -t cifs -o username=<username>,password=<pass>,dir_mode=0777,file_mode=0777,nounix //192.168.0.2/Path1/ /media/Path1

docker-compose.yml

node:
  volumes:
    - /media/Path1:/Path1

Do not forget:

docker-compose up -d 

Now the access (/Path1/…) from n8n works with the cmd node!

1 Like