# How to read files on Raspberry Pi

**URL:** <https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377>\
**Category:** General\
**Created:** [3 September 2020 02:09 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377 "2020-09-03T02:09:14Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 02:09 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/1 "2020-09-03T02:09:15Z")

</div>

I want to know how to use fill in node in Raspberry Pi.

On Windows, I need to use escape path separators, for example: \Users\myUser.  
But in Raspberry Pi I don't know how to fill in the address of the document.

Below is the json code of my process:

```auto
[
    {
        "id": "99d8cb51.cf4ce8",
        "type": "tab",
        "label": "test fill",
        "disabled": false,
        "info": ""
    },
    {
        "id": "348e443f.2578ac",
        "type": "inject",
        "z": "99d8cb51.cf4ce8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 380,
        "wires": [
            [
                "eb7198f5.d48468"
            ]
        ]
    },
    {
        "id": "21ee1722.c20778",
        "type": "debug",
        "z": "99d8cb51.cf4ce8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 360,
        "wires": []
    },
    {
        "id": "eb7198f5.d48468",
        "type": "function",
        "z": "99d8cb51.cf4ce8",
        "name": "",
        "func": "var tmp = new Date(msg.payload);\nmsg.payload = tmp\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 320,
        "y": 380,
        "wires": [
            [
                "21ee1722.c20778"
            ]
        ]
    },
    {
        "id": "cc9b4c3d.eb30c",
        "type": "inject",
        "z": "99d8cb51.cf4ce8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 140,
        "wires": [
            [
                "bd1f76a0.ec28e8"
            ]
        ]
    },
    {
        "id": "bd1f76a0.ec28e8",
        "type": "function",
        "z": "99d8cb51.cf4ce8",
        "name": "",
        "func": "msg.filename = \"\\\\/:home\\\\pi\\\\1.txt\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 290,
        "y": 180,
        "wires": [
            [
                "a941e8b1.478778"
            ]
        ]
    },
    {
        "id": "e09e72a5.45955",
        "type": "debug",
        "z": "99d8cb51.cf4ce8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 120,
        "wires": []
    },
    {
        "id": "a941e8b1.478778",
        "type": "file in",
        "z": "99d8cb51.cf4ce8",
        "name": "",
        "filename": "",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "x": 460,
        "y": 200,
        "wires": [
            [
                "e09e72a5.45955"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 05:16 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/2 "2020-09-03T05:16:35Z")

</div>

Hi @Ian  
Up the top of the edit window (see picture) there is an icon like: `</>`

You press that then paste the code.

![Screenshot from 2020-09-03 15-14-50](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/16370ddeedfcc61d000cb9644a089be3edd69e3b.png)

Makes it easier for people to get access to it.

Mind trying again?

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 05:25 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/3 "2020-09-03T05:25:04Z")

</div>

😂

```auto
[{"id":"d5830d92.707c1","type":"tab","label":"test rpi","disabled":false,"info":""},{"id":"62596014.67924","type":"inject","z":"d5830d92.707c1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":320,"wires":[["5f100b5c.cb1d64"]]},{"id":"4b11cf91.fd6","type":"debug","z":"d5830d92.707c1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":320,"wires":[]},{"id":"f49e35c1.2260f8","type":"file in","z":"d5830d92.707c1","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":610,"y":320,"wires":[["4b11cf91.fd6"]]},{"id":"5f100b5c.cb1d64","type":"function","z":"d5830d92.707c1","name":"","func":"msg.filename=\"\\\\home\\\\pi\\\\1.txt\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":320,"wires":[["f49e35c1.2260f8"]]},{"id":"2dfdfc6c.a56f14","type":"function","z":"d5830d92.707c1","name":"function","func":"// initialise the counter to 0 if it doesn't exist already\nvar dcount = global.get('dcount')||0;\ndcount += 1;\n \n// store the value back\nglobal.set('dcount',dcount);\n\nvar __dirname = \"\\\\home\\\\pi\";\n\nmsg.path =__ dirname;\nmsg.dirctory = \"newDirctory_\" + dcount;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"// 节点正在停止或重新部署时，将运行此处添加的代码。 \ncount = 0;","x":540,"y":520,"wires":[["45e61d3c.c23824"]]},{"id":"a55cbf07.29c8c","type":"inject","z":"d5830d92.707c1","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":350,"y":520,"wires":[["2dfdfc6c.a56f14"]]},{"id":"45e61d3c.c23824","type":"fs-ops-mkdir","z":"d5830d92.707c1","name":"mkdir","path":"path","pathType":"msg","dirname":"dirctory","dirnameType":"msg","mode":"777","fullpath":"directory","fullpathType":"msg","x":770,"y":520,"wires":[[]]}]`Preformatted text`

```

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 05:31 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/4 "2020-09-03T05:31:01Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a983167cb0e161d7125f5c624c6af25ab41d83f1.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fb89f4eaba21934b2c0dea7c0eefba63167d900b.png)  
I do't know how to fill in the address of the document.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 05:34 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/5 "2020-09-03T05:34:28Z")

</div>

Ah. Ok.

Oh, that post. Still not good. There is some stuff that (somehow) got stuck on the end.

Something about `Preformatted text`  
(How did you export the code)

But to your question:

Node-red is _sandboxed_ in how it works.

I'm sure there are ways to break out of the sandbox, but for the sake of explaining I am not going to go there.

It is in the `settings.js` file which is in the `.node-red` directory.

You will need to read stuff on how to set that up for file access.

I'm not even going to try and explain it. I'm still learning myself.

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 05:34 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/6 "2020-09-03T05:34:32Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7e0f9a5e17054a41a451340f08976b6d26a3b38.png)  
no such file or directory, open 'file'"

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 05:36 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/7 "2020-09-03T05:36:53Z")

</div>

[Try this](https://nodered.org/docs/user-guide/runtime/configuration)

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 05:42 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/8 "2020-09-03T05:42:15Z")

</div>

thank you，I tried this code and it works fine.

```auto
[{"id":"d5830d92.707c1","type":"tab","label":"test rpi","disabled":false,"info":""},{"id":"62596014.67924","type":"inject","z":"d5830d92.707c1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":320,"wires":[["5f100b5c.cb1d64"]]},{"id":"4b11cf91.fd6","type":"debug","z":"d5830d92.707c1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":320,"wires":[]},{"id":"f49e35c1.2260f8","type":"file in","z":"d5830d92.707c1","name":"","filename":"file","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":610,"y":320,"wires":[["4b11cf91.fd6"]]},{"id":"5f100b5c.cb1d64","type":"function","z":"d5830d92.707c1","name":"","func":"msg.filename=\"\\\\home\\\\pi\\\\1.txt\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":320,"wires":[["f49e35c1.2260f8"]]},{"id":"2dfdfc6c.a56f14","type":"function","z":"d5830d92.707c1","name":"function","func":"// initialise the counter to 0 if it doesn't exist already\nvar dcount = global.get('dcount')||0;\ndcount += 1;\n \n// store the value back\nglobal.set('dcount',dcount);\n\nvar __dirname = \"\\\\home\\\\pi\";\n\nmsg.path =__ dirname;\nmsg.dirctory = \"newDirctory_\" + dcount;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"// 节点正在停止或重新部署时，将运行此处添加的代码。 \ncount = 0;","x":540,"y":520,"wires":[["45e61d3c.c23824"]]},{"id":"a55cbf07.29c8c","type":"inject","z":"d5830d92.707c1","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":350,"y":520,"wires":[["2dfdfc6c.a56f14"]]},{"id":"45e61d3c.c23824","type":"fs-ops-mkdir","z":"d5830d92.707c1","name":"mkdir","path":"path","pathType":"msg","dirname":"dirctory","dirnameType":"msg","mode":"777","fullpath":"directory","fullpathType":"msg","x":770,"y":520,"wires":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 05:42 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/9 "2020-09-03T05:42:53Z")

</div>

Good. So what is the problem again?

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 05:47 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/10 "2020-09-03T05:47:42Z")

</div>

The problem is the same as at the beginning, the file cannot be read. Because it is running nodered on Raspberry Pi, it is different from windows. I don't know how to fill in the access address.

Maybe it’s wrong to fill in like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/07cd8dc2b47a7e574558370a714ad1eb6bcc3f54.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 06:19 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/11 "2020-09-03T06:19:25Z")

</div>

I don't know that is allowed.

Have you read the link I sent?

That is all about sharing and accessing files.

I don't think the double \ are helping either.

Normally I think it should be:

`"\home\pi\1.txt"`

As said: I am a learner. read the link and I hope that will help you.

---

<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:** [3 September 2020 06:41 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/12 "2020-09-03T06:41:00Z")

</div>

I am on my phone so can't look at the flow at the moment, but in case it helps you can use forward slashes on Windows, and I think you must use forward slashes on Linux, so use forward everywhere and the escape problem is no more.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 06:45 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/13 "2020-09-03T06:45:55Z")

</div>

Ah, yes. Silly me.

`"/home/pi/1.txt"`

See how silly I am.

Show me a bad example and I am confused.

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 06:49 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/14 "2020-09-03T06:49:47Z")

</div>

The problem is ok now.  
First need to create a new file under the docker

> docker exec -it mynodered bash  
> mkdir home/pi  
> touch 1.txt  
> vi 1.txt ## to add something like "hello"

because the nodered running under the docker of Raspberry Pi.  
so it just can read file under the docker.

> ./home/pi/1.txt  
> now it is ok.

```auto
[{"id":"d5830d92.707c1","type":"tab","label":"test rpi","disabled":false,"info":""},{"id":"62596014.67924","type":"inject","z":"d5830d92.707c1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":290,"y":320,"wires":[["f49e35c1.2260f8"]]},{"id":"4b11cf91.fd6","type":"debug","z":"d5830d92.707c1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":320,"wires":[]},{"id":"f49e35c1.2260f8","type":"file in","z":"d5830d92.707c1","name":"","filename":"./home/pi/1.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":540,"y":320,"wires":[["4b11cf91.fd6"]]},{"id":"5f100b5c.cb1d64","type":"function","z":"d5830d92.707c1","name":"","func":"msg.filename=\"\\/root\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":160,"wires":[[]]},{"id":"2dfdfc6c.a56f14","type":"function","z":"d5830d92.707c1","name":"function","func":"// initialise the counter to 0 if it doesn't exist already\nvar dcount = global.get('dcount')||0;\ndcount += 1;\n \n// store the value back\nglobal.set('dcount',dcount);\n\nvar __dirname = \"\\\\/\";\n\nmsg.path =__ dirname;\nmsg.dirctory = \"newDirctory_\" + dcount;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"// 节点正在停止或重新部署时，将运行此处添加的代码。 \ncount = 0;","x":540,"y":520,"wires":[["45e61d3c.c23824"]]},{"id":"a55cbf07.29c8c","type":"inject","z":"d5830d92.707c1","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":350,"y":520,"wires":[["2dfdfc6c.a56f14"]]},{"id":"45e61d3c.c23824","type":"fs-ops-mkdir","z":"d5830d92.707c1","name":"mkdir","path":"path","pathType":"msg","dirname":"dirctory","dirnameType":"msg","mode":"777","fullpath":"directory","fullpathType":"msg","x":770,"y":520,"wires":[[]]}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2cc30bbdbd168aaa1bcb12782ab4654fbf893e27.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 September 2020 06:58 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/15 "2020-09-03T06:58:57Z")

</div>

> [@lan](#):
>
> mkdir home/pi

Where is this `home/pi` in the scheme of things?

Because (given this is a RasPi) there should be (already) a directory `home/pi`

But you are talking `docker` so I can't really say.

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 07:22 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/16 "2020-09-03T07:22:10Z")

</div>

> [@Trying\_to\_learn](#):
>
> Where is this `home/pi` in the scheme of things?

Yes,in RasPi already a directory `home/pi`  
but，there is no such directory in docker.  
because the nodered running under the docker of Raspberry Pi.  
I created a directory under nodered of docker.`home/pi`  
[Running under Docker](https://nodered.org/docs/getting-started/docker)

Your answer(`"/home/pi/1.txt"`) is very helpful to me，thank you！

---

<div class="post-metadata">

**Author:** ![lan](https://avatars.discourse-cdn.com/v4/letter/l/df788c/32.png) [@lan](https://discourse.nodered.org/u/lan)\
**Post date:** [3 September 2020 07:29 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/17 "2020-09-03T07:29:17Z")

</div>

`mkdir home/pi` has some problem  
should use

> mkdir home  
> cd home  
> mkdir pi

---

<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:** [17 September 2020 07:29 UTC](https://discourse.nodered.org/t/how-to-read-files-on-raspberry-pi/32377/18 "2020-09-17T07:29:28Z")

</div>

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