# Problem in creating 1 CSV file for 1 day (Auto Logger)

**URL:** https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225
**Category:** General
**Tags:** database
**Created:** [4 April 2023 01:04 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225 "2023-04-04T01:04:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![jagades](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jagades/32/75744_2.png) [@jagades](https://discourse.nodered.org/u/jagades)
#### Post date: [4 April 2023 01:04 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/1 "2023-04-04T01:04:40Z")

</div>

Hello, I want to store my temperature data in csv files, specifically for data logging purpose. Now, I have developed till having bulk data in a single csv file. The csv file containing bulk data is as below:--

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f89160c4f585fdc7e17e646af7c1c125d21a68cb.png)  
I have been trying out the auto logger function from [Auto Logger: log data in daily CSV files (flow) - Node-RED](https://flows.nodered.org/flow/4f0653905120f422cc4f37cd5512ee14) and also closely following the YouTube video related to it. But, I still can't manage to create a csv file for 1 day.

I suspect this issue may be caused by destination file path. The original author used raspian to do the auto logging, which is a little different when setting destination path for csv files to be created. I will also share my flow below, hope anyone can help me out with this. Thanks.

```auto
[
    {
        "id": "10ebb9340ed6672a",
        "type": "tab",
        "label": "CopyTest",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "82315f6ced6cb1f7",
        "type": "C-Mode Command",
        "z": "10ebb9340ed6672a",
        "name": "CJ2M",
        "plcSeries": "CSJP",
        "hostNumber": 0,
        "headerCode": "RD",
        "p1": "1",
        "p2": "12",
        "p3": "",
        "x": 290,
        "y": 100,
        "wires": [
            [
                "bbc2a4c482c2abeb"
            ]
        ]
    },
    {
        "id": "01dd82772b927aa4",
        "type": "C-Mode Response",
        "z": "10ebb9340ed6672a",
        "name": "",
        "x": 630,
        "y": 100,
        "wires": [
            [
                "b73e2823222911f7"
            ]
        ]
    },
    {
        "id": "9834ad26f4c14af8",
        "type": "inject",
        "z": "10ebb9340ed6672a",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 100,
        "wires": [
            [
                "82315f6ced6cb1f7"
            ]
        ]
    },
    {
        "id": "bbc2a4c482c2abeb",
        "type": "serial request",
        "z": "10ebb9340ed6672a",
        "name": "",
        "serial": "1888161b22bfcc1a",
        "x": 430,
        "y": 100,
        "wires": [
            [
                "01dd82772b927aa4"
            ]
        ]
    },
    {
        "id": "f0a4c6b149cf6893",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 1,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 16",
        "format": "<font size=6>{{msg.payload.asInteger1[0]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 220,
        "wires": []
    },
    {
        "id": "4c18e5fa21894be7",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 2,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 51",
        "format": "<font size=6>{{msg.payload.asInteger1[1]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 260,
        "wires": []
    },
    {
        "id": "3b6516f0aabeaaa9",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 3,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 50",
        "format": "<font size=6>{{msg.payload.asInteger1[2]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 300,
        "wires": []
    },
    {
        "id": "1435cdec99e3e12d",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 4,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 49",
        "format": "<font size=6>{{msg.payload.asInteger1[3]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 340,
        "wires": []
    },
    {
        "id": "6e427aabe484a390",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 5,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 52",
        "format": "<font size=6>{{msg.payload.asInteger1[4]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 380,
        "wires": []
    },
    {
        "id": "28ecf406d4eb6696",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 6,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 44",
        "format": "<font size=6>{{msg.payload.asInteger1[5]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 420,
        "wires": []
    },
    {
        "id": "6b991ebe0f2ee636",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 7,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 17",
        "format": "<font size=6>{{msg.payload.asInteger1[6]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 460,
        "wires": []
    },
    {
        "id": "14d68d230c9b0b9f",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 8,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 46",
        "format": "<font size=6>{{msg.payload.asInteger1[7]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 500,
        "wires": []
    },
    {
        "id": "11b5682dc498d13b",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 9,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 45",
        "format": "<font size=6>N/A °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 540,
        "wires": []
    },
    {
        "id": "fc9503650488a150",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 10,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 47",
        "format": "<font size=6>{{msg.payload.asInteger1[9]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 580,
        "wires": []
    },
    {
        "id": "a06f33e04a0a2246",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 11,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 43",
        "format": "<font size=6>{{msg.payload.asInteger1[10]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 620,
        "wires": []
    },
    {
        "id": "cd996f876b16b6e9",
        "type": "ui_text",
        "z": "10ebb9340ed6672a",
        "group": "efcc13e5a5b82fc5",
        "order": 12,
        "width": 3,
        "height": 4,
        "name": "",
        "label": "<font size=7>Oven 42",
        "format": "<font size=6>{{msg.payload.asInteger1[11]}} °C",
        "layout": "col-center",
        "className": "num1",
        "x": 560,
        "y": 660,
        "wires": []
    },
    {
        "id": "bc9a53146f78d174",
        "type": "ui_template",
        "z": "10ebb9340ed6672a",
        "group": "",
        "name": "",
        "order": 1,
        "width": 0,
        "height": 0,
        "format": "<style>\n.num1 {\nborder: 2px solid #666;\nbackground-color : #b0e0f5 !important;\n}\n\n</style>",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": true,
        "templateScope": "global",
        "className": "",
        "x": 720,
        "y": 60,
        "wires": [
            []
        ]
    },
    {
        "id": "8f38c8065805b26e",
        "type": "file",
        "z": "10ebb9340ed6672a",
        "name": "",
        "filename": "C:\\Users\\user\\Desktop\\Oven3.csv",
        "filenameType": "str",
        "appendNewline": true,
        "createDir": false,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 1020,
        "y": 700,
        "wires": [
            []
        ]
    },
    {
        "id": "b73e2823222911f7",
        "type": "buffer-parser",
        "z": "10ebb9340ed6672a",
        "name": "",
        "data": "payload.buffer",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "int16be",
                "name": "asInteger1",
                "offset": 0,
                "length": 12,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "hex",
                "name": "asHex1",
                "offset": 0,
                "length": 2,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "hex",
                "name": "asHex2",
                "offset": 0,
                "length": 3,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "hex",
                "name": "hex3",
                "offset": 0,
                "length": 4,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "hex",
                "name": "hex4",
                "offset": 0,
                "length": 5,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "hex",
                "name": "hex5",
                "offset": 0,
                "length": 6,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 890,
        "y": 100,
        "wires": [
            [
                "f0a4c6b149cf6893",
                "4c18e5fa21894be7",
                "3b6516f0aabeaaa9",
                "1435cdec99e3e12d",
                "6e427aabe484a390",
                "28ecf406d4eb6696",
                "6b991ebe0f2ee636",
                "14d68d230c9b0b9f",
                "11b5682dc498d13b",
                "fc9503650488a150",
                "a06f33e04a0a2246",
                "cd996f876b16b6e9",
                "f64d36fe81b3382f"
            ]
        ]
    },
    {
        "id": "47ffcce3c170f0d0",
        "type": "comment",
        "z": "10ebb9340ed6672a",
        "name": "Auto Logger",
        "info": "",
        "x": 190,
        "y": 840,
        "wires": []
    },
    {
        "id": "348c985828bb2ff3",
        "type": "function",
        "z": "10ebb9340ed6672a",
        "name": "Filename generator",
        "func": "// Get the current time and convert it to text\nvar now = new Date();\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\n\n// Generate out file name pattern\nmsg.fname = \"\"+ dd + mm + yyyy + \".csv\";\n// Full filename with path for the file node later\nmsg.filename = \"C:\\\\Users\\\\user\\\\Desktop\\\\OvenData\\\\Temp\"+ msg.fname;\n\n// We save the current payload into a different place on the msg object\nmsg.filecontent = msg.payload;\n\n// We are passing the file name search pattern to fs node to tell us if the file exists or not\nmsg.payload = {\"pattern\":msg.fname};\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.fname});\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 190,
        "y": 780,
        "wires": [
            [
                "dae65afa5f5537d6"
            ]
        ]
    },
    {
        "id": "7ffbe2a0d3991bea",
        "type": "debug",
        "z": "10ebb9340ed6672a",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 590,
        "y": 820,
        "wires": []
    },
    {
        "id": "82fac3d413877343",
        "type": "switch",
        "z": "10ebb9340ed6672a",
        "name": "",
        "property": "$count(msg.payload)",
        "propertyType": "jsonata",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 610,
        "y": 780,
        "wires": [
            [
                "3efc398531b373ba"
            ],
            [
                "4dc6e8778c7f0b2e"
            ]
        ]
    },
    {
        "id": "320df14ef86ff3aa",
        "type": "csv",
        "z": "10ebb9340ed6672a",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "all",
        "multi": "one",
        "ret": "\\r\\n",
        "temp": "DateTime,Oven16,Oven51,Oven50,Oven49,Oven52,Oven44,Oven17,Oven46,Oven47,Oven43,Oven42",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 950,
        "y": 760,
        "wires": [
            [
                "6a086d4e774cc6d4"
            ]
        ]
    },
    {
        "id": "6a086d4e774cc6d4",
        "type": "file",
        "z": "10ebb9340ed6672a",
        "name": "",
        "filename": "filename",
        "filenameType": "msg",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "none",
        "x": 1110,
        "y": 760,
        "wires": [
            []
        ]
    },
    {
        "id": "3287e3a972356844",
        "type": "csv",
        "z": "10ebb9340ed6672a",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "none",
        "multi": "one",
        "ret": "\\r\\n",
        "temp": "DateTime,Oven16,Oven51,Oven50,Oven49,Oven52,Oven44,Oven17,Oven46,Oven47,Oven43,Oven42",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 950,
        "y": 800,
        "wires": [
            [
                "6a086d4e774cc6d4"
            ]
        ]
    },
    {
        "id": "3efc398531b373ba",
        "type": "change",
        "z": "10ebb9340ed6672a",
        "name": "Get file content",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "filecontent",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 760,
        "wires": [
            [
                "320df14ef86ff3aa"
            ]
        ]
    },
    {
        "id": "4dc6e8778c7f0b2e",
        "type": "change",
        "z": "10ebb9340ed6672a",
        "name": "Get file content",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "filecontent",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 800,
        "wires": [
            [
                "3287e3a972356844"
            ]
        ]
    },
    {
        "id": "dae65afa5f5537d6",
        "type": "fs-file-lister",
        "z": "10ebb9340ed6672a",
        "name": "",
        "start": "C:\\Users\\user\\Desktop\\OvenData\\Temp",
        "pattern": "",
        "folders": "*",
        "hidden": true,
        "lstype": "both",
        "path": true,
        "single": true,
        "depth": 0,
        "stat": true,
        "showWarnings": false,
        "x": 400,
        "y": 780,
        "wires": [
            [
                "7ffbe2a0d3991bea",
                "82fac3d413877343"
            ]
        ]
    },
    {
        "id": "f64d36fe81b3382f",
        "type": "function",
        "z": "10ebb9340ed6672a",
        "name": "Temp log",
        "func": "var d = new Date();\nvar date = d.getFullYear() + \"/\" + (d.getMonth() + 1) + \"/\" + d.getDate() + \" \" + d.getHours() + \":\" + d.getMinutes() + \":\" + d.getSeconds();\nvar ov1 = msg.payload.asInteger1[0];\nvar ov2 = msg.payload.asInteger1[1];\nvar ov3 = msg.payload.asInteger1[2];\nvar ov4 = msg.payload.asInteger1[3];\nvar ov5 = msg.payload.asInteger1[4];\nvar ov6 = msg.payload.asInteger1[5];\nvar ov7 = msg.payload.asInteger1[6];\nvar ov8 = msg.payload.asInteger1[7];\nvar ov9 = msg.payload.asInteger1[9];\nvar ov10 = msg.payload.asInteger1[10];\nvar ov11 = msg.payload.asInteger1[11];\nvar data = date + \",\" + ov1 + \",\" + ov2 + \",\" + ov3 + \",\" + ov4 + \",\" + ov5 + \",\" + ov6 + \",\" + ov7 + \",\" + ov8 + \",\" + ov9 + \",\" + ov10 + \",\" + ov11;\nmsg.payload = data;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 780,
        "y": 700,
        "wires": [
            [
                "8f38c8065805b26e",
                "348c985828bb2ff3"
            ]
        ]
    },
    {
        "id": "1888161b22bfcc1a",
        "type": "serial-port",
        "serialport": "COM7",
        "serialbaud": "9600",
        "databits": "7",
        "parity": "even",
        "stopbits": "2",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\n",
        "bin": "false",
        "out": "char",
        "addchar": "",
        "responsetimeout": "3000"
    },
    {
        "id": "efcc13e5a5b82fc5",
        "type": "ui_group",
        "name": "OVEN MONITORING DASHBOARD",
        "tab": "8d9d162b9ddf43a5",
        "order": 2,
        "disp": true,
        "width": "12",
        "collapse": false,
        "className": ""
    },
    {
        "id": "8d9d162b9ddf43a5",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c28ab19f54bc2b7bdbb6ff6f983f4c0d03dcd2b.png)  
This is my destination path to store my csv files.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [4 April 2023 01:12 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/2 "2023-04-04T01:12:39Z")

</div>

I've not tyied your flow and I don't know auto logger.

But the answer is to use a change or function node to set the file name for the file write node dynamically and include a date in the file name.

With a change node, you should be able to do that with a JSONata input. You are aiming for a filename that looks like:

```auto
/path/to/my/filename-20230404.csv

```

As long as the date part is dynamically created on each run through the flow, and the file write is set to append, any outputs would accumulate through the day and a new file would be created each new day. However, if I've read your flow correctly, I think you may be outputting the full CSV each time? If so, you would not want to accumulate the output, simply overwrite each time.

If you do need to accumulate through the day, you probably need to drop any column header row on all outputs except the first of the day. That would be a bit more complex to set up.

---

<div class="post-metadata">

### Author: ![jagades](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jagades/32/75744_2.png) [@jagades](https://discourse.nodered.org/u/jagades)
#### Post date: [4 April 2023 02:37 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/3 "2023-04-04T02:37:38Z")

</div>

> [@TotallyInformation](#):
>
> But the answer is to use a change or function node to set the file name for the file write node dynamically and include a date in the file name

I believe I have done this in my flow :--

```auto
// Get the current time and convert it to text
var now = new Date();
var yyyy = now.getFullYear();
var mm = now.getMonth() < 9 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based
var dd = now.getDate() < 10 ? "0" + now.getDate() : now.getDate();
var hh = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
var mmm = now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();

// Generate out file name pattern
msg.fname = ""+ dd + mm + yyyy + ".csv";
// Full filename with path for the file node later
msg.filename = "C:/Users/user/Desktop/OvenData"+ msg.fname;

// We save the current payload into a different place on the msg object
msg.filecontent = msg.payload;

// We are passing the file name search pattern to fs node to tell us if the file exists or not
msg.payload = {"pattern":msg.fname};

node.status({fill:"blue",shape:"ring",text:msg.fname});
return msg;

```

Just that when I use my destination file path, I cannot use it directly into the function node, simply because the function node expects a hex digit.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c59d40b23d68dcc4054db2581e6c627721546509.png)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [4 April 2023 06:56 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/5 "2023-04-04T06:56:15Z")

</div>

Try escaping the \ characters with another . Eg. c:\\Users\\user\\ etc

---

<div class="post-metadata">

### Author: ![jagades](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jagades/32/75744_2.png) [@jagades](https://discourse.nodered.org/u/jagades)
#### Post date: [4 April 2023 07:10 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/6 "2023-04-04T07:10:57Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e8420ce4a6bcf6e8abc2bea3898add3a711a5f9e.png)

Tried this, but the csv file ended up being created at the desktop and not inside the destination path.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96bc5b6f325d742d97977499756e94ca712a5198.png)  
Plus the file being created is not named as intended.

---

<div class="post-metadata">

### Author: ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)
#### Post date: [4 April 2023 08:27 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/7 "2023-04-04T08:27:35Z")

</div>

> [@jagades](#):
>
> file ended up being created at the desktop

that is where you intended it to be, as per `msg.filename` may be you require another \\ after PMC ?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [4 April 2023 08:45 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/8 "2023-04-04T08:45:53Z")

</div>

> [@jagades](#):
>
> `msg.filename = "C:/Users/user/Desktop/OvenData"+ msg.fname`

Should be:

```auto
msg.filename = "C:/Users/user/Desktop/OvenData/"+ msg.fname

```

or better still:

```auto
msg.filename = `C:/Users/user/Desktop/OvenData/${msg.fname}`

```

Simple case of a missing slash. Unfortunately, you didn't say at the start that a file was being created correctly - just in the wrong place.

---

<div class="post-metadata">

### Author: ![jagades](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jagades/32/75744_2.png) [@jagades](https://discourse.nodered.org/u/jagades)
#### Post date: [4 April 2023 09:11 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/9 "2023-04-04T09:11:18Z")

</div>

Tried this, but the file is yet not storing in the destination folder.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1d4961369d6e330990d7b44171d3b62cd47b7d01.png)

> [@TotallyInformation](#):
>
> Unfortunately, you didn't say at the start that a file was being created correctly - just in the wrong place.

I got the wrong path file creation only after @dceejay 's suggestion. Initially I didn't get to create any files.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [4 April 2023 13:46 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/10 "2023-04-04T13:46:35Z")

</div>

Have you checked whether the file really exists? It is possible that the file lister node might be wrong.

---

<div class="post-metadata">

### Author: ![jagades](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jagades/32/75744_2.png) [@jagades](https://discourse.nodered.org/u/jagades)
#### Post date: [7 April 2023 02:55 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/11 "2023-04-07T02:55:27Z")

</div>

> [@TotallyInformation](#):
>
> Have you checked whether the file really exists?

I checked by searching at the windows search toolbar, but the file was not found.

> [@TotallyInformation](#):
>
> It is possible that the file lister node might be wrong

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7e6bf3600c09807f73118f58e72abc3fa594132d.png)  
I created a folder and placed it on desktop, and copied its path. But the files are not stored in here/anywhere in my computer.

---

<div class="post-metadata">

### Author: ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)
#### Post date: [7 April 2023 06:49 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/12 "2023-04-07T06:49:19Z")

</div>

Put double backslashes in the start folder too: `C:\\Users\\user\\Desktop\\PMC`

Edit: Then the files inside this folder are found at least. Not sure about the other problems you're facing.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [7 April 2023 07:36 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/13 "2023-04-07T07:36:07Z")

</div>

I think it is better to always use forward slashes, which, I believe, work perfectly well in Windows. Then you remove the escaping problem completely.

---

<div class="post-metadata">

### Author: ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)
#### Post date: [7 April 2023 07:57 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/14 "2023-04-07T07:57:44Z")

</div>

Tried to be consistent with @dceejay's comment. Forward slashes `C:/Users/user/Desktop/PMC` work as well.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [7 April 2023 07:58 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/15 "2023-04-07T07:58:53Z")

</div>

yeah I'm too old school... / is a much better answer.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [7 April 2023 09:05 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/16 "2023-04-07T09:05:56Z")

</div>

Just to say though that you do not need `\\` in the file read/write nodes. I know that because I've been using them to transform some data for work.

But yes, in general, `/` is easier to work with when using things like Python and JavaScript.

---

<div class="post-metadata">

### Author: ![jagades](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jagades/32/75744_2.png) [@jagades](https://discourse.nodered.org/u/jagades)
#### Post date: [8 April 2023 04:15 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/17 "2023-04-08T04:15:12Z")

</div>

Update 😄  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/60b3d096e9895d3d4232095187614c3827deaf9d.png)  
I've created csv files for 1 day and it can be found by the file lister node too.

```auto
msg.filename = "C:\\Users\\user\\Desktop\\PMC\\" + msg.fname;

```

This should be the format for the files to be assigned to store in the destination path,

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/974ecaa0ed926ae5833ef0cedb3191a97330433c.png)  
and this is the path for the file lister node.

The result :--

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bfad1491fc07a1402e1881d50167741aa2485e81.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/a/9aed32cce20d76c0a1664626f5b05538271f6e5b.png)  
Thanks to all who offered ideas and solutions. Now I'll have to see how to remove the blank row between the data.

---

<div class="post-metadata">

### Author: ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)
#### Post date: [8 April 2023 04:24 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/18 "2023-04-08T04:24:09Z")

</div>

nice of you to post the final outcome, so it is useful for any future user reading through this thread.

---

<div class="post-metadata">

### Author: ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)
#### Post date: [8 April 2023 08:43 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/19 "2023-04-08T08:43:28Z")

</div>

> [@jagades](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/974ecaa0ed926ae5833ef0cedb3191a97330433c.png)

Oddly this works now. Do you know what the problem was?

---

<div class="post-metadata">

### Author: ![jagades](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jagades/32/75744_2.png) [@jagades](https://discourse.nodered.org/u/jagades)
#### Post date: [10 April 2023 00:43 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/20 "2023-04-10T00:43:10Z")

</div>

[https://flows.nodered.org/flow/4f0653905120f422cc4f37cd5512ee14](https://flows.nodered.org/flow/4f0653905120f422cc4f37cd5512ee14)  
I suspect the problem was from incorrect backslash usage.

So what I did was :--

1. Go to the link and copy the flow posted.
2. Import the flow and test out the flow according to your device (pi or mini pc).
3. Fake the data temporarily by injecting a timestamp containing integers.
4. Make sure that the csv file is being created, and the file lister node detects the file.
5. Only then adapt this flow into your original work flow by removing the fake data timestamp and replacing with the actual data (like serial read data from PLC).

This is the example of the flow I modified for csv file creation, before adapting the input data to my actual flow. You can simply change the file path and test the flow out.

```auto
[
    {
        "id": "572e656e2b1868e3",
        "type": "tab",
        "label": "Flow 2",
        "disabled": true,
        "info": "",
        "env": []
    },
    {
        "id": "f79c29b7.055068",
        "type": "comment",
        "z": "572e656e2b1868e3",
        "name": "Auto Logger",
        "info": "",
        "x": 90,
        "y": 360,
        "wires": []
    },
    {
        "id": "4c8ae605.33be88",
        "type": "function",
        "z": "572e656e2b1868e3",
        "name": "Set data",
        "func": "\nvar d = new Date();\nvar date = d.getFullYear() + \"/\" + (d.getMonth() + 1) + \"/\" + d.getDate() + \" \" + d.getHours() + \":\" + d.getMinutes() + \":\" + d.getSeconds();\n\nmsg.payload = {\n \"Date&Time\": date,\n \"Oven1\": 2+3,\n \"Oven2\" :1111+3,\n \"Oven3\" :2222,\n \"Oven4\" :3333,\n \"Oven5\" :4444,\n \"Oven6\" :5555,\n \"Oven7\" :6666,\n \"Oven8\" :7777,\n \"Oven9\" :8888,\n \"Oven10\" :9999,\n \"Oven11\" :10101,\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 160,
        "y": 580,
        "wires": [
            [
                "f46f569e.ff1a08"
            ]
        ]
    },
    {
        "id": "f46f569e.ff1a08",
        "type": "function",
        "z": "572e656e2b1868e3",
        "name": "Filename generator",
        "func": "// Get the current time and convert it to text\nvar d = new Date();\nvar yyyy = d.getFullYear();\nvar mm = d.getMonth() < 9 ? \"0\" + (d.getMonth() + 1) : (d.getMonth() + 1); // getMonth() is zero-based\nvar dd = d.getDate() < 10 ? \"0\" + d.getDate() : d.getDate();\nvar hh = d.getHours() < 10 ? \"0\" + d.getHours() : d.getHours();\nvar mmm = d.getMinutes() < 10 ? \"0\" + d.getMinutes() : d.getMinutes();\nvar ss = d.getSeconds() < 10 ? \"0\" + d.getSeconds() : d.getSeconds();\n\n// Generate out file name pattern\nmsg.fname = \"m\"+ yyyy + mm + dd + \".csv\";\n// Full filename with path for the file node later\nmsg.filename = \"C:\\\\Users\\\\user\\\\Desktop\\\\PMC\\\\\"+ msg.fname;\n\n// We save the current payload into a different place on the msg object\nmsg.filecontent = msg.payload;\n\n// We are passing the file name search pattern to fs node to tell us if the file exists or not\nmsg.payload = {\"pattern\":msg.fname};\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.fname});\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 210,
        "y": 740,
        "wires": [
            [
                "fa6936f.7758dc8"
            ]
        ]
    },
    {
        "id": "a96494a5.b0f4c8",
        "type": "debug",
        "z": "572e656e2b1868e3",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 600,
        "wires": []
    },
    {
        "id": "3db97537.b889ea",
        "type": "switch",
        "z": "572e656e2b1868e3",
        "name": "",
        "property": "$count(msg.payload)",
        "propertyType": "jsonata",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 510,
        "y": 660,
        "wires": [
            [
                "3cb887e8.e533a8"
            ],
            [
                "f3ba1c7a.54ef5"
            ]
        ]
    },
    {
        "id": "fe6f74d5.674ec8",
        "type": "csv",
        "z": "572e656e2b1868e3",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "all",
        "multi": "one",
        "ret": "\\r\\n",
        "temp": "Date&Time,Oven1,Oven2,Oven3,Oven4,Oven5,Oven6,Oven7,Oven8,Oven9,Oven10,Oven11",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 850,
        "y": 640,
        "wires": [
            [
                "3a8ebdf3.772cc2"
            ]
        ]
    },
    {
        "id": "3a8ebdf3.772cc2",
        "type": "file",
        "z": "572e656e2b1868e3",
        "name": "",
        "filename": "filename",
        "filenameType": "msg",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "none",
        "x": 1000,
        "y": 660,
        "wires": [
            []
        ]
    },
    {
        "id": "f226a86d.9bdfb8",
        "type": "csv",
        "z": "572e656e2b1868e3",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "none",
        "multi": "one",
        "ret": "\\r\\n",
        "temp": "Date&Time,Oven1,Oven2,Oven3,Oven4,Oven5,Oven6,Oven7,Oven8,Oven9,Oven10,Oven11",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 850,
        "y": 680,
        "wires": [
            [
                "3a8ebdf3.772cc2"
            ]
        ]
    },
    {
        "id": "3cb887e8.e533a8",
        "type": "change",
        "z": "572e656e2b1868e3",
        "name": "Get file content",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "filecontent",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 680,
        "y": 640,
        "wires": [
            [
                "fe6f74d5.674ec8"
            ]
        ]
    },
    {
        "id": "f3ba1c7a.54ef5",
        "type": "change",
        "z": "572e656e2b1868e3",
        "name": "Get file content",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "filecontent",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 680,
        "y": 680,
        "wires": [
            [
                "f226a86d.9bdfb8"
            ]
        ]
    },
    {
        "id": "fa6936f.7758dc8",
        "type": "fs-file-lister",
        "z": "572e656e2b1868e3",
        "name": "",
        "start": "C:\\Users\\user\\Desktop\\PMC\\",
        "pattern": "",
        "folders": "*",
        "hidden": true,
        "lstype": "files",
        "path": true,
        "single": true,
        "depth": 0,
        "stat": true,
        "showWarnings": false,
        "x": 300,
        "y": 660,
        "wires": [
            [
                "a96494a5.b0f4c8",
                "3db97537.b889ea"
            ]
        ]
    },
    {
        "id": "2561887c3874f25c",
        "type": "inject",
        "z": "572e656e2b1868e3",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "2",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 400,
        "wires": [
            [
                "4c8ae605.33be88"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [24 April 2023 00:43 UTC](https://discourse.nodered.org/t/problem-in-creating-1-csv-file-for-1-day-auto-logger/77225/21 "2023-04-24T00:43:28Z")

</div>

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