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

**URL:** <https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854>\
**Category:** General\
**Created:** [4 June 2019 22:41 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854 "2019-06-04T22:41:50Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [4 June 2019 22:41 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/1 "2019-06-04T22:41:50Z")

</div>

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.

Thanks

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [5 June 2019 01:08 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/2 "2019-06-05T01:08:55Z")

</div>

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

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

```

---

<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:** [5 June 2019 09:10 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/3 "2019-06-05T09:10:03Z")

</div>

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

Nice! and I now have learned something new today!

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [5 June 2019 17:41 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/4 "2019-06-05T17:41:53Z")

</div>

> [@zenofmud](#):
>
> I'm using node-red-contrib-fso

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 !

---

<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:** [5 June 2019 17:46 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/5 "2019-06-05T17:46:48Z")

</div>

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

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.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [6 June 2019 17:19 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/6 "2019-06-06T17:19:39Z")

</div>

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

`[payload[$not($match(/^[.]/))]]`

`[payload[$match(/^[^.]/)]]`

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

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

`[payload~>$filter(/^\w/)]`

and probably many more...

---

<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:** [6 June 2019 18:49 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/7 "2019-06-06T18:49:05Z")

</div>

@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 🙂

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [6 June 2019 18:53 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/8 "2019-06-06T18:53:29Z")

</div>

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".

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [6 June 2019 19:32 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/9 "2019-06-06T19:32:18Z")

</div>

> [@shrickus](#):
>
> `[payload[$substringBefore(".")]]` _(not exactly sure why that works?!?)_

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.

---

<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:** [6 June 2019 19:52 UTC](https://discourse.nodered.org/t/ideas-to-remove-an-entry-starting-with-a-period-from-an-array-of-filenames/11854/10 "2019-06-06T19:52:09Z")

</div>

> [@shrickus](#):
>
> regex is not very "human-readable".

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.

![43%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7e870b275e10ce4deecc99b5b1ff0b1203b5aac9.png)
