Ideas to remove an entry starting with a period from an array of filenames?

I'm using node-red-contrib-fs-ops to get a list of the files in a folder. The names of the files are returned in an array. However it is also returning the hidden files (ones starting with a period) and I don't want them.

My brain is fried from watching grand kids and I'm trying to figure out how to get rid of the files with a period. I suppose I could code a function with a loop to look at the entry and if it starts with a period, pop it off the array,

Just wondering if someone has a better/cleverer/easier idea.


Using filter on the array in a function node should get you what you need...

var input = ["one", ".two", "three"];
var output = input.filter(item => item[0] == '.' ? null : item);

Nice! and I now have learned something new today!

Hi Paul, could you please confirm the name of the contrib node ? I wanted to have a look at it but failed to find by the name node-red-contrib-fso in the library. Thank you !

See I told you my brain was fried. the node is node-red-contrib-fs-ops :woozy_face:

p.s. I fixed it in the original post

Just for info, I'm building a little music player for my daughter to put in her waiting room. The walls of her new office are not very sound proof and she is a therapist.

I have an old 3" Cambridge Sounsworks speaker, a Pi Zero W and a HiFiBerry DAC hat that sits on the Pi. I created a folder on the Pi called Sounds. Because I use a mac and copy files to the Pi from the finder, a file called .AppleDouble gets created and I wanted to get rid of it.

1 Like

Of course, you can also use one of these lovely JSONata expressions in a change node:



[payload[$substringBefore(".")]] (not exactly sure why that works?!?)

[payload[$substring(0,1) != "."]]


and probably many more...

@shrickus Steve...Nice, they almost all work great! I like [payload[$substring(0,1) != "."]] - it makes sence to me.

[payload~>$filter(/^\w/)] has a problem, it gets rid of every other file so if there are 18 filenames and the first has a period, you get 1, 3, 5, 7, 9, 11, 13, 15 and 17 returned :slightly_smiling_face:

Ah, yes, i think the filter function takes 2 args... sorry about that -- I guess my dataset was too small to notice that behavior ;*)

Yep, I'd use the one that makes the most sense to you, especially when you go back to look at it next month... and regex is not very "human-readable".

This one is good. Deserves its own topic. I have a similar use case that is a puzzle to me. I will open the topic, make a remark and ask for feedback and will try to find the other case.

Regex makes my brain hurt. I was using a function node to get rid of the dotted files and count them, now I'm just using a change node with two jssonata expressions - works great.