# What is best practice to get files with jpg as file extension

**URL:** https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526
**Category:** General
**Created:** [12 May 2021 06:03 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526 "2021-05-12T06:03:00Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![tpbillund](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tpbillund/32/37410_2.png) [@tpbillund](https://discourse.nodered.org/u/tpbillund)
#### Post date: [12 May 2021 06:03 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/1 "2021-05-12T06:03:00Z")

</div>

Hi

atm. im using the watch node on a folder, it shows what is happening in the folder, both when I correct, create and delete files.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4aa86c53550ba40d4ede68c86bb2f19b0edd29b.png)

What I want is to just look at which files are being created and they should only be .jpg files.  
So my first question is:

- How can I get a hit, about which files are created, I have no interest in what is deleted or changed.  
Next:
- To get only one hit on .jpg files, is it so best to use a switch node where I find out to look at my payload around \* .jpg and so that way get my hits sent on .jpg files?  
Or is it a better / second option?

---

<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: [12 May 2021 10:43 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/2 "2021-05-12T10:43:24Z")

</div>

Why not use a `switch` node after the `watch` Node using the ‘contains’ option and jpeg as the value. So in English it would be “if msg.payload contains ‘jpeg’’

---

<div class="post-metadata">

### Author: ![tpbillund](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tpbillund/32/37410_2.png) [@tpbillund](https://discourse.nodered.org/u/tpbillund)
#### Post date: [12 May 2021 13:25 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/3 "2021-05-12T13:25:57Z")

</div>

okay as I wrote, but using the "contains" 🙂 Thx.  
What about the question about created files, atm. it will "hit me" if I delete, modify or create a new JPG file, and I need it only to work if created.

---

<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: [12 May 2021 16:40 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/4 "2021-05-12T16:40:32Z")

</div>

The node can't possibly tell what has changed. What you could try is use node-red-contrib-fs to read the directory and store that information. Then when the `watch` node triggers you could use the `fs-file-lister` to get the info for that file and compare if against the saved information and determine what has happened to the file.

---

<div class="post-metadata">

### Author: ![tpbillund](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tpbillund/32/37410_2.png) [@tpbillund](https://discourse.nodered.org/u/tpbillund)
#### Post date: [13 May 2021 05:15 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/5 "2021-05-13T05:15:55Z")

</div>

Hi  
I used the "Watch-directory" from node-red-contrib-watchdirectory.  
And it works well, as wanted.  
Thx.

---

<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: [13 May 2021 07:44 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/6 "2021-05-13T07:44:43Z")

</div>

Nice, I hadn’t seen that node before. Nice find!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [13 May 2021 08:20 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/7 "2021-05-13T08:20:10Z")

</div>

Indeed - would make a good update to the core node.

---

<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: [27 May 2021 08:20 UTC](https://discourse.nodered.org/t/what-is-best-practice-to-get-files-with-jpg-as-file-extension/45526/8 "2021-05-27T08:20:44Z")

</div>

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