# Automatic create new file&directiry everyday

**URL:** <https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764>\
**Category:** General\
**Created:** [1 July 2019 04:05 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764 "2019-07-01T04:05:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppungpong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppungpong/32/9494_2.png) [@ppungpong](https://discourse.nodered.org/u/ppungpong)\
**Post date:** [1 July 2019 04:05 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/1 "2019-07-01T04:05:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [1 July 2019 04:11 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/2 "2019-07-01T04:11:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ppungpong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppungpong/32/9494_2.png) [@ppungpong](https://discourse.nodered.org/u/ppungpong)\
**Post date:** [1 July 2019 04:19 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/3 "2019-07-01T04:19:41Z")

</div>

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

 ![AA](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ede88d3e5d9d193b447b302ea41004757fe2b606.png)

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

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [1 July 2019 04:25 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/4 "2019-07-01T04:25:56Z")

</div>

Specifically, which part?

---

<div class="post-metadata">

**Author:** ![ppungpong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppungpong/32/9494_2.png) [@ppungpong](https://discourse.nodered.org/u/ppungpong)\
**Post date:** [1 July 2019 06:06 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/5 "2019-07-01T06:06:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [1 July 2019 06:41 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/6 "2019-07-01T06:41:15Z")

</div>

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

Is it not easier to use a dynamic filename ?

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [1 July 2019 07:06 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/7 "2019-07-01T07:06:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 July 2019 07:24 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/8 "2019-07-01T07:24:53Z")

</div>

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](https://www.influxdata.com/time-series-database/)

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](https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/amp/) and you don't need to worry about filenames etc.

---

<div class="post-metadata">

**Author:** ![ppungpong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppungpong/32/9494_2.png) [@ppungpong](https://discourse.nodered.org/u/ppungpong)\
**Post date:** [5 July 2019 02:26 UTC](https://discourse.nodered.org/t/automatic-create-new-file-directiry-everyday/12764/9 "2019-07-05T02:26:04Z")

</div>

Thx. I will try.
