List files local directory (file name Strings)

New to Node Red
created a flow with a readdir node - debug indicates the node is picking up all the files in the directory as a complete path (all good here)
What I am not sure of is how to make this a drop down (single choice) with just the file names no directory information (even better with a .XXX extension filter for MP4 file types)

unsure of how to execute this?

Hi and welcome.

This is very vague, you do not mention what the data is, string, array or object etc. You really should supply an example of the data. Also is this dropdown displaying just a file name but outputting the complete path?
Please show us the output require from the input supplied.

Execute can be vague.

String array

Still none of the information requested, I will ask one more time for an example of the data and output.

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

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 ```)

``` 
   code goes here 
```

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

See this post for more details - How to share code or flow json

Yup.

As I understand it you want a list of MP4 files in a given directory, but not the full pathname?

I'd do it with an exec node ls /home/ian/media/*.mp4 or cd /home/ian/media/; ls *.mp4 but then I use Linux. I dare say other operating systems offer similar functions.

Currently I get a list of strings which includes the file name as well as the full Path

Only the file name is critical. As the directories are synced with a remote machine. Which is looking only the file name as it already knows the path to pickup the file.

The impetus behind getting a file list and selecting one is to ensure 1 the file should exist on the remote machine, and the file name matches exactly.

Hope that explains it

this is the degug window and the array from the node [file lister]

["Defaultvideo.mp4","HDTV pattern.jpg","hummingbird.mp4","PostVideo.mp4","Prevideo.mp4"]

the next step is to have this data display as choices in a dropdown UI node -this will be used to construct a msg to the remote manchine

Without the full info i asked for and answers to the questions i asked i can only offer this example.

Hope it helps, it should create an options array for node-red-dashboard, containing only mp4 file names.

[{"id":"0c6a37e001738edf","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"Defaultvideo.mp4\",\"HDTV pattern.jpg\",\"hummingbird.mp4\",\"PostVideo.mp4\",\"Prevideo.mp4\"]","payloadType":"json","x":230,"y":5600,"wires":[["a881122d87f140df"]]},{"id":"a881122d87f140df","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload[$substring($, -4) = \".mp4\"].{$:$}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":5600,"wires":[["48856e2089e8c664","4ff46e05d0f1a28c"]]},{"id":"48856e2089e8c664","type":"debug","z":"d1395164b4eec73e","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":5600,"wires":[]},{"id":"4ff46e05d0f1a28c","type":"ui_dropdown","z":"d1395164b4eec73e","name":"","label":"","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":1,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":540,"y":5640,"wires":[[]]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"Demo","tab":"0ca01f1e15e69b4d","order":2,"disp":true,"width":"18","collapse":false,"className":""},{"id":"0ca01f1e15e69b4d","type":"ui_tab","name":"demo","icon":"dashboard","disabled":false,"hidden":false}]

How to import/export a flow

1 Like

worked a treat thx

1 Like

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