Automatic create new file&directiry everyday

How to create new file in every day sort by date, like 07/06/2019 and next day will be 08/06/2019 etc. and also have data in those file too. I don't know how to start it.

Start by looking through the node palette to see which nodes might work with each of your tasks.

I would look at nodes like inject, file, sort and moment as they seem to be the most logical fit. And where is this "data" coming from?

I have data come from the sensor and store it into local raspberry pi

In node palette, I feel confuse about what node that might I want -..-

Specifically, which part?

I save data .csv 4 parts, and will store it everyday new directory

For directories you will need to use an exec node and create the directory.

Is it not easier to use a dynamic filename ?

[{"id":"39df7856.3dc74","type":"file in","z":"681f8bde.8887bc","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":446,"y":572,"wires":[[]]},{"id":"568dc58a.1f2c0c","type":"function","z":"681f8bde.8887bc","name":"","func":"let d = new Date().toISOString().slice(0, 10);\nlet f = '/home/pi/Sensor/earth_leakage/earth_leakage_'+d+'.csv';\nreturn {filename:f};","outputs":1,"noerr":0,"x":292,"y":550,"wires":[["e938dbf6.4d86a","39df7856.3dc74"]]},{"id":"e938dbf6.4d86a","type":"debug","z":"681f8bde.8887bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":446,"y":528,"wires":[]},{"id":"bfd075cc.19be98","type":"inject","z":"681f8bde.8887bc","name":"set filename","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":136,"y":550,"wires":[["568dc58a.1f2c0c"]]}]

The file out node has a checkbox to Create directory if it doesn't exist?


Alternative suggestions...

At a guess, you want historical data and perhaps you then send this CSV to a database? Or you open in in excel to analyse / create charts/reports etc? If so, I'd suggest you have a look at sending your data to a database instead of files. Far more efficient and more future possibilities. There are many nodes and many types of database possibilities in node-red. A suggestion for sensor data would be a time-series database like InfluxDB

However, if you just want logs, for later inspection, then I suggest you consider at installing node-red-contrib-flogger. It's a node designed for logging. Couple that with logrotate and you don't need to worry about filenames etc.

1 Like

Thx. I will try.