# Function or Node to get the modified date from a file

**URL:** <https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156>\
**Category:** General\
**Created:** [17 February 2021 12:21 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156 "2021-02-17T12:21:38Z")\
**Posts on this page:** 9\
**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:** [17 February 2021 12:21 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/1 "2021-02-17T12:21:38Z")

</div>

Hi  
I need to look at this file, and if it's modified within the last 2 sec. then that will run a flow.  
/config/www/snapshots/foran\_detection\_latest.jpg

I just don't know where to start with a function or what Node too use, in my case.

Can someone guide me ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 February 2021 12:39 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/2 "2021-02-17T12:39:41Z")

</div>

Hi and welcome.

Have you tried the watch node?

---

<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:** [17 February 2021 12:46 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/3 "2021-02-17T12:46:34Z")

</div>

Hi and Thx. 🙂

Is it this one ?  
[node-red-contrib-watchdirectory (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-watchdirectory)

Then yes and can see that i can "Type event : update" but how do I look at it and see if it's within 3 sec. from now ?

---

<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:** [17 February 2021 12:59 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/4 "2021-02-17T12:59:37Z")

</div>

Ahh the build-in watch, no..  
I add the filepath and filename to the name, and then i'm stuck.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 February 2021 13:01 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/5 "2021-02-17T13:01:32Z")

</div>

The watch node is a core node and pre installed, you can watch for any changes to a file. So if a file is updated the watch node should catch it. No need to wait 3 seconds.

Add a debug then update the file and see what you get in the debug node.

---

<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:** [17 February 2021 13:10 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/6 "2021-02-17T13:10:33Z")

</div>

@E1cid  
What... 🙂  
Was it so easy... sry then... but then I hope I can ask in addition to this.  
Can see the debug note gives me 7..

> 2/17/2021, 2:05:12 PM[node: 5d07bda.8a8d144](http://172.25.100.228:8123/api/hassio_ingress/AloR6roe4NSW5vJID9x2iHD97XlgyZ0DVsZcbNrxYtY/#)/config/www/snapshots/terrasse\_detection\_latest.jpg : msg.payload : string[51]
> 
> "/config/www/snapshots/terrasse\_detection\_latest.jpg"

That will trigger a flow 7 time for the same update.. right?  
If so, how do I get it to run only once for each update.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 February 2021 13:23 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/7 "2021-02-17T13:23:59Z")

</div>

Filter msg using trigger node, to only receive one.  
e.g.

```auto
[{"id":"dfed8e71.e5e8c8","type":"trigger","z":"5a245aa1.510164","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"250","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":360,"y":1760,"wires":[["3f35d274.99189e"]]},{"id":"cda23beb.ee4ea","type":"split","z":"5a245aa1.510164","name":"simulate 7 msg","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":390,"y":1700,"wires":[["dfed8e71.e5e8c8"]]},{"id":"3f35d274.99189e","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":1760,"wires":[]},{"id":"7e3a17af.07e5","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,1,1,1,1,1,1]","payloadType":"json","x":150,"y":1680,"wires":[["cda23beb.ee4ea"]]}]

```

---

<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:** [17 February 2021 13:29 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/8 "2021-02-17T13:29:52Z")

</div>

wow thx. it helped alot, and is working...

---

<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:** [3 March 2021 13:30 UTC](https://discourse.nodered.org/t/function-or-node-to-get-the-modified-date-from-a-file/41156/9 "2021-03-03T13:30:46Z")

</div>

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