Populate dropdown node help needed

I want to populate the dashboard dropdown node with a list of whatever .jpg files are present in a folder which is located on a usb stick pugged into my pi, when I open the dropdown in the dashboard I want to be able to choose one of the file names in the drop down list and have it sent to the output of the dropdown node.
I can get a list of files using the exec node with cmd ls /media/usbPEN/nas/snap/
result is a string as see picture below...
The problem I have is how do I populate the Value / Label field for each file name into the dropdown node.

Help would be appreciated.

image

There is readdir node, node-red-contrib-readdir (node) - Node-RED which does the job all in one action . Reads the directory, puts result in array, and sets it to the msg.options so can be feed directly to the dropdown node.

image

1 Like

That sounds brilliant ill try that for sure .. thanks for your help.

I find the fs-ops node set better for file and directory operations.

You can get an array of files (with our without a wildcard) then pass that to the other fs-ops nodes to do other actions.

YMMV.

hotNipi
That readdir node is awesome, I've been scratching my head all afternoon trying things before I asked for help, thanks again for this info its brilliant, I am so happy..

Steve-Mci
ill take a look at the fs-ops node tomorrow, the readdir node is going to take some beating though, thanks for your input.

Me again .. I have one further question .. I want to send the directory path into the readdir node however I'm struggling to find a solution, unlike say the file nodes were you send msg.filename the Directory field cannot be left blank, I tried msg.payload {{msg.payload}} path, directory, dir in there but nothing appears to work , HOW ?

image

Did someone say fs-ops?

OK OK I've moved over to fs-ops successfully, only criticism the colour of the nodes are yuk, hahah

1 Like

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