# File lister: path in variable

**URL:** <https://discourse.nodered.org/t/file-lister-path-in-variable/83926>\
**Category:** General\
**Created:** [21 December 2023 15:30 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926 "2023-12-21T15:30:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Medestrac](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Medestrac](https://discourse.nodered.org/u/Medestrac)\
**Post date:** [21 December 2023 15:30 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/1 "2023-12-21T15:30:46Z")

</div>

Hi,  
I need to check if a file already exist in a folder.  
I use "file-lister" from node-red-contrib-fs, and it works well, but only if I give it the folder, for example: Start Folder = C:/Users/me/flows/  
This folder is already in a flow variable, so I want to use something like:  
Start Folder = flow.myFolder...but it doesn't work.  
Can someone help me with this?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [21 December 2023 15:39 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/2 "2023-12-21T15:39:57Z")

</div>

Try using a `change` node just before the file lister node. Then you can set msg.path to flow.myFolder and pass it to the file lister node.

---

<div class="post-metadata">

**Author:** ![Medestrac](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Medestrac](https://discourse.nodered.org/u/Medestrac)\
**Post date:** [22 December 2023 07:29 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/3 "2023-12-22T07:29:22Z")

</div>

Ok, I've put the change node and set msg.path before the file lister node.  
How should I configure the file lister node?  
I've tried to set Start Folder to "nothing" / msg / msg.path / flow.myFolder but nothing works except the hard-coded C:/Users/me/flows/

---

<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:** [22 December 2023 10:31 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/4 "2023-12-22T10:31:42Z")

</div>

At the bottom of the help text for the node it tells you how to define the path in a message:  
" To override the configured options, pass in a msg with msg.payload like: `{"start":"/my/folder","pattern":"*.json","folders":"!context"}` Any missing options will be picked up from the configured node."

So a Change node configured something like this should do it  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b804b2fc46ac7d9abfcef4fd7c0d1495024d67db.png)

---

<div class="post-metadata">

**Author:** ![Medestrac](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Medestrac](https://discourse.nodered.org/u/Medestrac)\
**Post date:** [22 December 2023 11:43 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/5 "2023-12-22T11:43:48Z")

</div>

Thanks, but the change node configuration is not the problem, I've an issue with the file lister configuration. I think it's just a syntax issue. What should I do in the "Start Folder"?  
It works with an hard-coded C:/Users/Me/flows/, and also with an environment variable ${MyFolder}  
but I don't know how to use a flow variable nor msg.path

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

---

<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:** [22 December 2023 11:49 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/6 "2023-12-22T11:49:32Z")

</div>

> [@Medestrac](#):
>
> I don't know how to use a flow variable nor msg.path

Read my post again, it is not msg.path that you need to use. The path must be passed in the payload, which you can do using a Change node as I suggested.

---

<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:** [22 December 2023 11:56 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/7 "2023-12-22T11:56:37Z")

</div>

Example flow

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

```auto
[{"id":"9dbd46e7994b500c","type":"change","z":"997da33a0beedade","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.start","pt":"msg","to":"myFolder","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":980,"wires":[["6df90bec1c9243ad"]]},{"id":"c1bcb8e684d8e758","type":"inject","z":"997da33a0beedade","name":"Get file list","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":980,"wires":[["9dbd46e7994b500c"]]},{"id":"6df90bec1c9243ad","type":"fs-file-lister","z":"997da33a0beedade","name":"","start":"/","pattern":"*.*","folders":"*","hidden":true,"lstype":"files","path":true,"single":false,"depth":0,"stat":false,"showWarnings":true,"x":540,"y":980,"wires":[["43d268a322a00bb8"]]},{"id":"43d268a322a00bb8","type":"debug","z":"997da33a0beedade","name":"debug 2473","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":980,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 December 2023 11:59 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/8 "2023-12-22T11:59:17Z")

</div>

That does not look to me like the `fs list` node. This is what I see when I open it.

 ![Screenshot 2023-12-22 at 6.55.49 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51745103804d02111f95bb05b93b4c60f4241215.jpeg)

Please export your node and paste it in a reply

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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:** [22 December 2023 12:14 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/9 "2023-12-22T12:14:19Z")

</div>

I assumed it is the one out of node-red-contrib-fs, as stated in the first post, which does have a Start Folder field.

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 December 2023 12:25 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/10 "2023-12-22T12:25:19Z")

</div>

My bad! I have both node-red-contrib-fs and node-red-contrib-filesystem installed and th 'filesystem' nodes show as  
 ![Screenshot 2023-12-22 at 7.24.13 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b4dc74bacf62e7a3d3fcec171cbfa624ab412385.png) and I was looking at fs list not fs - file - lister

---

<div class="post-metadata">

**Author:** ![Medestrac](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Medestrac](https://discourse.nodered.org/u/Medestrac)\
**Post date:** [22 December 2023 12:26 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/11 "2023-12-22T12:26:37Z")

</div>

Here is a simplified version of my code.  
The file lister is the one from node-red-contrib-fs

```auto
[
    {
        "id": "d557afe07f574c0f",
        "type": "tab",
        "label": "Flux 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "3a8b9d456b1084e3",
        "type": "inject",
        "z": "d557afe07f574c0f",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 270,
        "y": 140,
        "wires": [
            [
                "9d764aca51045d52"
            ]
        ]
    },
    {
        "id": "9d764aca51045d52",
        "type": "function",
        "z": "d557afe07f574c0f",
        "name": "function 9",
        "func": "var folder = \"C:/Users/Me/flows/\" \n\nvar file = \"myfile.csv\"\n\nmsg.fname = file\nmsg.filename = folder + file\n\nmsg.filecontent = msg.payload;\nmsg.payload = { \"pattern\": msg.fname };\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 140,
        "wires": [
            [
                "73e73b91f8cd8675"
            ]
        ]
    },
    {
        "id": "73e73b91f8cd8675",
        "type": "fs-file-lister",
        "z": "d557afe07f574c0f",
        "name": "",
        "start": "C:/Users/Me/flows/",
        "pattern": "",
        "folders": "*",
        "hidden": true,
        "lstype": "files",
        "path": true,
        "single": true,
        "depth": 0,
        "stat": true,
        "showWarnings": false,
        "x": 620,
        "y": 140,
        "wires": [
            [
                "71388be84dc2fb5f"
            ]
        ]
    },
    {
        "id": "71388be84dc2fb5f",
        "type": "switch",
        "z": "d557afe07f574c0f",
        "name": "Test si fichier existe",
        "property": "$count(msg.payload)",
        "propertyType": "jsonata",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 810,
        "y": 140,
        "wires": [
            [
                "42d026e6a3f1aab3"
            ],
            [
                "920657f2b92d9946"
            ]
        ]
    },
    {
        "id": "d93f27d25ef29295",
        "type": "csv",
        "z": "d557afe07f574c0f",
        "name": "Génère fichier + en-tête",
        "sep": ",",
        "hdrin": "",
        "hdrout": "all",
        "multi": "one",
        "ret": "\\r",
        "temp": "Time, Antenne, Data",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 1260,
        "y": 120,
        "wires": [
            [
                "ab86f6a722296074"
            ]
        ]
    },
    {
        "id": "4d3fa0c630e9e96b",
        "type": "csv",
        "z": "d557afe07f574c0f",
        "name": "Ajoute ligne au fichier",
        "sep": ",",
        "hdrin": "",
        "hdrout": "none",
        "multi": "one",
        "ret": "\\n",
        "temp": "Time, Antenne, Data",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 1260,
        "y": 160,
        "wires": [
            [
                "ab86f6a722296074"
            ]
        ]
    },
    {
        "id": "42d026e6a3f1aab3",
        "type": "change",
        "z": "d557afe07f574c0f",
        "name": "Get file content",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "filecontent",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1030,
        "y": 120,
        "wires": [
            [
                "d93f27d25ef29295"
            ]
        ]
    },
    {
        "id": "920657f2b92d9946",
        "type": "change",
        "z": "d557afe07f574c0f",
        "name": "Get file content",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "filecontent",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1030,
        "y": 160,
        "wires": [
            [
                "4d3fa0c630e9e96b"
            ]
        ]
    },
    {
        "id": "ab86f6a722296074",
        "type": "file",
        "z": "d557afe07f574c0f",
        "name": "",
        "filename": "filename",
        "filenameType": "msg",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "none",
        "x": 1500,
        "y": 140,
        "wires": [
            []
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 December 2023 12:33 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/12 "2023-12-22T12:33:28Z")

</div>

If you read the `help` for the dnode you will see

`To override the configured options, pass in a msg with msg.payload like: {"start":"/my/folder","pattern":"*.json","folders":"!context"} Any missing options will be picked up from the configured node.`

Your function node you have this:

```auto
msg.payload = { "pattern": msg.fname };

```

which is not what the node wants

---

<div class="post-metadata">

**Author:** ![Medestrac](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Medestrac](https://discourse.nodered.org/u/Medestrac)\
**Post date:** [22 December 2023 12:47 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/13 "2023-12-22T12:47:47Z")

</div>

That's it!  
I was missing `{"start":"/my/folder"`}.  
With this it's alright:

```auto
var folder = flow.get("myFolder")
msg.payload = {"start":folder, "pattern": msg.fname };

```

Thanks guys!

---

<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:** [5 January 2024 12:48 UTC](https://discourse.nodered.org/t/file-lister-path-in-variable/83926/14 "2024-01-05T12:48:17Z")

</div>

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